-
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
Slow performance of std::iter::Rev with iterator adapters using std::iter::Iterator::nth() #54054
Comments
I would probably call this |
I ran into this issue as well I think. I was expecting |
If I get the time later, I'll make a PR to add an |
Add DoubleEndedIterator::nth_back As suggested by rust-lang#54054. This doesn't fix that issue, as this doesn't add enough implementations to optimise that specific use case, but it adds the method and a few (relatively) trivial overrides to work as an initial implementation. It's probably going to be a lot of work adding `nth_back` implementations everywhere, and I don't have the time to include it all in this commit. But, it's a start. :)
Add DoubleEndedIterator::nth_back As suggested by rust-lang#54054. This doesn't fix that issue, as this doesn't add enough implementations to optimise that specific use case, but it adds the method and a few (relatively) trivial overrides to work as an initial implementation. It's probably going to be a lot of work adding `nth_back` implementations everywhere, and I don't have the time to include it all in this commit. But, it's a start. :)
Add DoubleEndedIterator::nth_back As suggested by rust-lang#54054. This doesn't fix that issue, as this doesn't add enough implementations to optimise that specific use case, but it adds the method and a few (relatively) trivial overrides to work as an initial implementation. It's probably going to be a lot of work adding `nth_back` implementations everywhere, and I don't have the time to include it all in this commit. But, it's a start. :)
Add DoubleEndedIterator::nth_back As suggested by rust-lang#54054. This doesn't fix that issue, as this doesn't add enough implementations to optimise that specific use case, but it adds the method and a few (relatively) trivial overrides to work as an initial implementation. It's probably going to be a lot of work adding `nth_back` implementations everywhere, and I don't have the time to include it all in this commit. But, it's a start. :)
With For example, the slice iterator has Lines 3802 to 3813 in 8ae730a
So it should probably have Line 3827 in 8ae730a
The general pattern here will be to just do whatever |
Thanks, I will look into implementing some of the |
Implement specialized nth_back() for Box and Windows. Hi there, this is my first pull request to rust :-) I started implementing some specializations for DoubleEndedIterator::nth_back() and these are the first two. The problem has been discussed in rust-lang#54054 and nth_back() is tracked in rust-lang#56995. I'm stuck with the next implementation so I though I do a PR for the ones I'm confident with to get some feedback.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
implement specialized nth_back() for Bytes, Fuse and Enumerate Hi, After my first PR has been successfully merged, here is my second pull request :-) Also this PR contains some specializations for the problem discussed in rust-lang#54054.
Implement nth_back for slice::{Iter, IterMut} Part of #54054. I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂 I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me. I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
Implement nth_back for slice::{Iter, IterMut} Part of #54054. I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂 I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me. I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
…tmcm Add Step::sub_usize Required for rust-lang#54054. I'm aware that the `Step` trait needs a rework, but this still seems like a reasonable addition? This currently doesn't compile because Chalk contains a type that implement this trait, and this is a breaking change. How can that be fixed?
…ottmcm Implement nth_back for RChunks(Exact)(Mut) Part of rust-lang#54054. These implementations may not be optimal because of the use of `self.len()`, but it's quite cheap and simplifies the code a lot. There's quite some duplication going on here, I wouldn't mind cleaning this up later. A good next step would probably be to add private `split_off_up_to`/`split_off_from` helper methods for slices since their behavior is commonly useful throughout the `Chunks` types. r? @scottmcm
…tmcm Add Step::sub_usize Required for rust-lang#54054. I'm aware that the `Step` trait needs a rework, but this still seems like a reasonable addition? This currently doesn't compile because Chalk contains a type that implement this trait, and this is a breaking change. How can that be fixed?
…ottmcm Implement nth_back for RChunks(Exact)(Mut) Part of rust-lang#54054. These implementations may not be optimal because of the use of `self.len()`, but it's quite cheap and simplifies the code a lot. There's quite some duplication going on here, I wouldn't mind cleaning this up later. A good next step would probably be to add private `split_off_up_to`/`split_off_from` helper methods for slices since their behavior is commonly useful throughout the `Chunks` types. r? @scottmcm
implement nth_back for Range(Inclusive) This is part of rust-lang#54054.
Add custom nth_back to Skip Implementation of nth_back for Skip. Part of rust-lang#54054
…=scottmcm Implement nth_back for slice::{Iter, IterMut} Part of rust-lang#54054. I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂 I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me. I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
Add custom nth_back for Chain Implementation of nth_back for Chain. Part of rust-lang#54054
…unksexactmut, r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of rust-lang#54054. r? @scottmcm
…unksexactmut, r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of rust-lang#54054. r? @scottmcm
…unksexactmut, r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of rust-lang#54054. r? @scottmcm
…unksexactmut, r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of rust-lang#54054. r? @scottmcm
Looks like |
The following example shows a benchmark of the iterator adapter
step_by()
. Once usingstep_by()
directly on the range and once with a redirection viarev()
.Running this benchmark with the current nightly shows these results:
step_by()
makes use ofnth()
of the adapted iterator. A range provides an optimized version ofnth()
, but by usingrev()
we get to use the default implementation ofnth()
.We should Extend
std::iter::DoubleEndedIterator
to provide a new method maybenth_back()
orrnth()
with a default implementation which then can get adapted byrev()
. Similar to the already existingnext_back()
,try_rfold()
,rfold()
andrfind()
.Update:
nth_back()
has been merged in #56802. Types which have a specializednth()
and implementDoubleEndedIterator
are candidates for a specializednth_back()
. The following list shows these candidates and their implementation status:nth_back
for ChunksExactMut #63265)The text was updated successfully, but these errors were encountered: