-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Use internal iteration in Vec::extend_desugared()
#138752
base: master
Are you sure you want to change the base?
Conversation
Because LLVM is unable to optimize well external iteration with some iterator kinds (e.g. `chain()`). To do that I had to hoist the `size_hint()` call to the beginning of the loop (since I no longer have access to the iterator inside the loop), which might slightly pessimize certain iterators that are able to give more accurate size bounds during iteration (e.g. `flatten()`). However, the effect should not be big, and also, common iterators like these also suffer from the external iteration optimizibility problem (e.g. `flatten()`).
Is there some sort of codegen test you could use to demonstrate that this has a beneficial effect? |
I'm pretty sure a benchmark will show a difference, but I will check. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
So, @compiler-errors, unlike what I thought, this is not a 100% win (never trust your instincts in performance!). I benchmarked three scenarios: a The results are: in the first two cases, the algorithms are almost equivalent, with a slight preference to the old algorithm for the first case and a slight preference to the new in the second case. In the third case, however, the new algorithm is almost 3x faster. So my conclusion is: one such operation is not bad, but once you start to add more this version is significantly faster. |
I think you could preserve the more precise length estimation by using |
Because LLVM is unable to optimize well external iteration with some iterator kinds (e.g.
chain()
).To do that I had to hoist the
size_hint()
call to the beginning of the loop (since I no longer have access to the iterator inside the loop), which might slightly pessimize certain iterators that are able to give more accurate size bounds during iteration (e.g.flatten()
). However, the effect should not be big, and also, common iterators like these also suffer from the external iteration optimizibility problem (e.g.flatten()
).