Skip to content

Specialize Zip::nth for TrustedRandomAccess - #48635

Merged
bors merged 3 commits into
rust-lang:masterfrom
scottmcm:faster-zip-nth
Mar 3, 2018
Merged

Specialize Zip::nth for TrustedRandomAccess#48635
bors merged 3 commits into
rust-lang:masterfrom
scottmcm:faster-zip-nth

Conversation

@scottmcm

Copy link
Copy Markdown
Member

Fixes the performance difference observed in https://users.rust-lang.org/t/performance-difference-between-iterator-zip-and-skip-order/15743

Before:

test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 4)
test iter::bench_zip_then_skip ... bench: 4,725 ns/iter (+/- 225)

After:

test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 2)
test iter::bench_zip_then_skip ... bench: 81 ns/iter (+/- 19)

Makes the bench asked about on URLO 58x faster :)
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 1, 2018
@kennytm

Copy link
Copy Markdown
Member

Could you add a test to ensure side effects are executed?

fnmain(){letmut a = Vec::new();letmut b = Vec::new();let value = (1..7).map(|n| {
a.push(n);
n *10}).zip((2..9).map(|n| {
b.push(n *100);
n *1000})).skip(1).nth(3);assert_eq!(value,Some((50,6000)));assert_eq!(a, vec![1,2,3,4,5]);assert_eq!(b, vec![200,300,400,500,600]);}

@scottmcm

Copy link
Copy Markdown
MemberAuthor

@kennytm Good call.

It looks like Range: !TrustedRandomAccess, though, so I swapped it out for cloning slice iterators.

Comment threadsrc/libcore/iter/mod.rs Outdated

#[inline]
default fn nth(&mut self, n: usize) -> Option<Self::Item>
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: why this { is on a new line 😄

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that is an excellent question 😅

Comment threadsrc/libcore/iter/mod.rs Outdated

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item>
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This also)

@kennytmkennytm added the T-libs-api [DEPRECATED; DO NOT USE] label Mar 1, 2018
@kennytm

Copy link
Copy Markdown
Member

Travis passed, so

@bors r+

@bors

bors commented Mar 1, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 5105fc1 has been approved by kennytm

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2018
@ManishearthManishearth mentioned this pull request Mar 2, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
Specialize Zip::nth for TrustedRandomAccess
Fixes the performance difference observed in https://users.rust-lang.org/t/performance-difference-between-iterator-zip-and-skip-order/15743
Before:
```
test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 4)
test iter::bench_zip_then_skip ... bench: 4,725 ns/iter (+/- 225)
```
After:
```
test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 2)
test iter::bench_zip_then_skip ... bench: 81 ns/iter (+/- 19)
```
@ManishearthManishearth mentioned this pull request Mar 3, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
@bors
bors merged commit 5105fc1 into rust-lang:masterMar 3, 2018
@scottmcm
scottmcm deleted the faster-zip-nth branch March 4, 2018 01:16
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@scottmcm@rust-highfive@kennytm@bors