-
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
Optimize slice_iter.copied().next_chunk()
#103166
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
Just my two cents, use |
This comment has been minimized.
This comment has been minimized.
f03bc4e
to
4dc0e6c
Compare
slice_iter.copied.next_chunk
slice_iter.copied().next_chunk()
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.
r=me :)
4dc0e6c
to
873a18e
Compare
@bors r=m-ou-se rollup |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#103166 (Optimize `slice_iter.copied().next_chunk()`) - rust-lang#103176 (Fix `TyKind::is_simple_path`) - rust-lang#103178 (Partially fix `src/test/run-make/coverage-reports` when cross-compiling) - rust-lang#103198 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…imulacrum Specialize `iter::ArrayChunks::fold` for TrustedRandomAccess iterators ``` OLD: test iter::bench_trusted_random_access_chunks ... bench: 368 ns/iter (+/- 4) NEW: test iter::bench_trusted_random_access_chunks ... bench: 30 ns/iter (+/- 0) ``` The resulting assembly is similar to rust-lang#103166 but the specialization kicks in under different (partially overlapping) conditions compared to that PR. They're complementary. In principle a TRA-based specialization could be applied to all `ArrayChunks` methods, including `next()` as we do for `Zip` but that would have all the same hazards as the Zip specialization. Only doing it for `fold` is far less hazardous. The downside is that it only helps with internal, exhaustive iteration. I.e. `for _ in` or `try_fold` will not benefit. Note that the regular, `try_fold`-based and the specialized `fold()` impl have observably slightly different behavior. Namely the specialized variant does not fetch the remainder elements from the underlying iterator. We do have a few other places in the standard library where beyond-the-end-of-iteration side-effects are being elided under some circumstances but not others. Inspired by https://old.reddit.com/r/rust/comments/yaft60/zerocost_iterator_abstractionsnot_so_zerocost/
The default
next_chunk
implementation suffers from having to assemble the array byte by byte vianext()
, checking theOption<&T>
and then dereferencing&T
. The specialization copies the chunk directly from the slice.