-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement iterator specialization traits on more adapters #85528
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 838b07beaca15f5614619bcee070ef5263a805ed with merge e056521d347c0ec9e2f6a0a140406f4b0a06c011... |
☀️ Try build successful - checks-actions |
Queued e056521d347c0ec9e2f6a0a140406f4b0a06c011 with parent 99e3aef, future comparison URL. |
Finished benchmarking try commit (e056521d347c0ec9e2f6a0a140406f4b0a06c011): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
Looks like noise. Or if it isn't then it's tiny impact at least. I guess the I'll write some benchmarks to see if these actually improve some assembly. |
3b3e1bb
to
5e1a4a3
Compare
I have added a benchmark
|
if Self::MAY_HAVE_SIDE_EFFECT && idx == 0 { | ||
for skipped_idx in 0..self.n { | ||
drop(try_get_unchecked(&mut self.iter, skipped_idx)); | ||
} |
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.
In light of #85969 I must note that this alters (undocumented) side-effects for backwards iteration, albeit in less surprising ways.
This block is written to preserve side-effects of the skipped portion of the iterator during forward iteration. During backward iteration it will lead to the whole skipped portion being drained on the last (backwards) step instead of only the first item beyond the skipped portion, i.e. it behaves as if the last item were obtained by a next()
instead of next_back()
.
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.
Hm, so, my interpretation of what you're saying: we're picking idx == 0
, which might not actually be the first index the user iterates over (and won't be in backwards iteration).
But I think my interpretation is probably wrong -- I've tried several times and I cannot manage to find a case where your patch causes different behavior in map(|i| dbg!(i)).skip(n)
behavior in forward or backward iteration. Do you have an example where it makes causes an observable difference?
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.
next_back
doesn't touch the inner's skipped prefix. But anything that goes backwards via __iterator_get_unchecked
(e.g. Zip
) would once it hits index 0.
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.
@the8472 Okay, this is a slight behavioral change to behavior we never made a promise about. I think it's a change we're allowed to make, but to be safe, that decision should be left to t-libs-api FCP.
Do you mind writing up the details about before/after differences so that that can be done?
Going to pass this one off because I'm not familiar enough with this part of r? @m-ou-se |
☔ The latest upstream changes (presumably #85874) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
FCP complete, this should be ready to merge. ping @Amanieu or reassign to a libs reviewer now that the libs-api question is settled. |
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.
Thank you! Nice work.
@bors r+ |
Implement iterator specialization traits on more adapters This adds * `TrustedLen` to `Skip` and `StepBy` * `TrustedRandomAccess` to `Skip` * `InPlaceIterable` and `SourceIter` to `Copied` and `Cloned` The first two might improve performance in the compiler itself since `skip` is used in several places. Constellations that would exercise the last point are probably rare since it would require an owning iterator that has references as Items somewhere in its iterator pipeline. Improvements for `Skip`: ``` # old test iter::bench_skip_trusted_random_access ... bench: 8,335 ns/iter (+/- 90) # new test iter::bench_skip_trusted_random_access ... bench: 2,753 ns/iter (+/- 27) ```
💥 Test timed out |
Apple runner hanging. @bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (fa40433): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 662.48s -> 663.269s (0.12%) |
This adds
TrustedLen
toSkip
andStepBy
TrustedRandomAccess
toSkip
InPlaceIterable
andSourceIter
toCopied
andCloned
The first two might improve performance in the compiler itself since
skip
is used in several places. Constellations that would exercise the last point are probably rare since it would require an owning iterator that has references as Items somewhere in its iterator pipeline.Improvements for
Skip
: