gaio icon indicating copy to clipboard operation
gaio copied to clipboard

allows WaitIO() to reuse the []OpResult slice

Open zjx20 opened this issue 3 years ago • 2 comments

每次调用WaitIO()都会新创建一个[]OpResult小对象,对性能造成一定影响;这个PR修改了WaitIO()的接口,允许用户传入一个预先分配好的slice,从而避免每次重新创建。

buf := make([]gaio.OpResult, 0, 100)
for {
  results, err := w.WaitIO(buf)
  ...
}

甚至用户可以直接重用返回的slice

buf := make([]gaio.OpResult, 0, 100)
for {
  results, err := w.WaitIO(buf)
  for _, r := range results {
    // ...
  }
  buf = results[:0]
}

image

zjx20 avatar Sep 17 '21 11:09 zjx20

this makes the interface compatible

xtaci avatar Jan 27 '24 08:01 xtaci

是的,不过修复起来也足够简单,加个 nil 就跟原来一样了;要么加一个 WaitIO2() ,一样很恶心;或者就不动了,留一个性能污点。

zjx20 avatar Jan 28 '24 02:01 zjx20