Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows WaitIO() to reuse the []OpResult slice #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zjx20
Copy link

@zjx20 zjx20 commented Sep 17, 2021

每次调用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

@xtaci
Copy link
Owner

xtaci commented Jan 27, 2024

this makes the interface compatible

@zjx20
Copy link
Author

zjx20 commented Jan 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants