-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Optimize unnecessary check in VecDeque::retain #88075
Conversation
Signed-off-by: Xuanwo <github@xuanwo.io>
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon. Please see the contribution instructions for more information. |
Signed-off-by: Xuanwo <github@xuanwo.io>
I ran the benchmark on my Mac
Before optimization:
After optimization:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@bors r+ rollup=never |
📌 Commit e32f4c0 has been approved by |
☀️ Test successful - checks-actions |
This pr is highly inspired by #88060 which shared the same idea: we can split the
for
loop into stages so that we can remove unnecessary checks likedel > 0
.Benchmarks
Before
After
Based on the current benchmark, this PR will improve the perf of
VecDeque::retain
by around 16%. For special cases, the improvement will be up to 30%.Signed-off-by: Xuanwo github@xuanwo.io