-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
fix(iter::skip): Optimize next
and nth
implementations of Skip
#96350
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @yaahc (or someone else) soon. Please see the contribution instructions for more information. |
What do you mean by "element is loaded"? Semantically this changes nothing because it still steps the iterator for Anyway, do you have assembly output or benchmarks that show that this is an improvement? |
I feel like this also fixes a potential bug: rust/library/core/src/iter/adapters/skip.rs Lines 35 to 38 in 5cdab3a
Doesn't this call Other the other hand the change proposed to |
I haven't dug that deep into this. The optimization was more on the amount of items yielded by the iterator, but I can dig into comparing the assembly output or benchmarking now. I feel like it mainly depends on the internal iterator though, so potentially opinionated. Was more opening to see if a possibility before digging in.
Yeah, does seem that this would be a bug for non-fused iterators. I'll open a separate PR for this so it isn't attached to this change. |
nvm @SkiFire13 this was previously correct because iterator docs states "Individual iterator implementations may choose to resume iteration, and so calling next() again may or may not eventually start returning Some(Item) again at some point." Going to revert the last commits changing this to exiting if the skip iterator returns |
eba8c69
to
4569f89
Compare
☔ The latest upstream changes (presumably #99451) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm currently taking a break from the review rotation and didn't realize this one is still assigned to me. Sorry about that. r? rust-lang/libs |
Please leave a comment with |
This comment has been minimized.
This comment has been minimized.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot ready |
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.
Please also avoid merge commits and instead rebase.
@rustbot author #96350 (comment) is also still missing a test, though I think the code has been adjusted in this PR. |
@rustbot ready |
I think the test referenced in #96350 (comment) is not yet added? |
This comment has been minimized.
This comment has been minimized.
3cd4ed4
to
f1f5e08
Compare
@rustbot ready Apologies for the lapse on the last fix (also, the comment for that specific test had not loaded for some reason) |
I will note that the logic of the skip iterator seems slightly broken no matter how it's implemented. The reason I had previously not exited early when loading the skip element is that Iterator docs state that once an iterator returns I totally get that avoiding panics for non-fused iterator is more important, but the reason I ask is I'm wondering if the documentation can be improved for |
One more nit and please squash the commits. |
f1f5e08
to
104bec4
Compare
104bec4
to
8f27b9a
Compare
8f27b9a
to
00bc9e8
Compare
@bors r+ rollup=iffy |
☀️ Test successful - checks-actions |
Finished benchmarking commit (80ed61f): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
This avoids calling nth/next or nth/nth to first skip elements and then get the next one (unless necessary due to usize overflow).