-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
core::Zip::next_back() slow for iterators of different lengths #147704
Copy link
Copy link
Open
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The following example is a benchmark of
core::Zip::next_back()with iterators of very different lengths.It outputs:
This is caused by
Zip::next_back()calling the longer iterator'snext_back()until both iterators are the same length. For iterators not implementingTrustedRandomAccessNoCoercethis could be sped up significantly by usingadvance_back_by()instead.I'm not sure if this can be optimised for iterators implementing
TrustedRandomAccessNoCoercebut notTrustedRandomAccess, as they use the samenext_back()implemntation but cannot safely useadvance_back_by().Rust version