-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Make Vec::push
as non-generic as possible
#91848
Conversation
As long as these functions are called after `needs_to_grow()`, the capacity overflow check has the same result as the special zero-sized type check. This commit removes that check, documents the `needs_to_grow()` constraint, and updates the test accordingly.
It reduces generated code size a bit more.
This factors out common code at the end of `RawVec::finish_grow_exact` and `RawVec::finish_grow_amortized`.
@bors try @rust-timer queue cc @SimonSapin, viz. #72013 (comment) |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 24041c3 with merge f09ca0f6143be1dbe123a38a376f2400b4a86e57... |
Results locally have been mixed. It definitely reduces the amount of LLVM IR generated. I think |
☀️ Try build successful - checks-actions |
Queued f09ca0f6143be1dbe123a38a376f2400b4a86e57 with parent f7fd79a, future comparison URL. |
Finished benchmarking commit (f09ca0f6143be1dbe123a38a376f2400b4a86e57): comparison url. Summary: This change led to large relevant mixed results 🤷 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
The So now I need to determine why that code path got slower, and if I can fix it. |
This is a tar pit. After many tries I can't do better than a mixture of improvements and regressions. Time to give up. |
Vec::push
is a frequently instantiated generic function, and reducing the amount of generic code in functions it calls (e.g.RawVec::grow_amortized
has been a performance win in the past, e.g. #72013, #91246. But some additional attempts also failed, e.g. #72189, #73912, #75093, #75129.This PR goes deeper than those old failed attemps. It makes
RawVec::grow_amortized()
about as non-generic as possible. Everything remaining in it involvesself
, or aT
-dependent operation, or is passing stuff to the non-genericfinish_grow_amortized()
.r? @ghost