Skip to content

Avoid Iterator::last - #101690

Merged
bors merged 1 commit into
rust-lang:masterfrom
kadiwa4:avoid_iterator_last
Sep 13, 2022
Merged

Avoid Iterator::last#101690
bors merged 1 commit into
rust-lang:masterfrom
kadiwa4:avoid_iterator_last

Conversation

@kadiwa4

Copy link
Copy Markdown
Contributor

Adapters like Filter and Map use the default implementation of Iterator::last which is not short-circuiting (and so does core::str::Split). The predicate function will be run for every single item of the underlying iterator. I hope that removing those calls to last results in slight performance improvements.

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 11, 2022
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbotrustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 11, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 11, 2022
@leonardo-m

Copy link
Copy Markdown

If this is a problem, has Clippy a "performance" suggestion about this? (Dogfooding compiler improvementes into Clippy is generally a good idea).

@kadiwa4

Copy link
Copy Markdown
ContributorAuthor

No, it doesn't look like a lint for that exists.

@Kobzol

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 12, 2022
@bors

bors commented Sep 12, 2022

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 66211d8 with merge 5bcf9d36a0c3bd58c90f463f91304174af29e909...

@bors

bors commented Sep 12, 2022

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 5bcf9d36a0c3bd58c90f463f91304174af29e909 (5bcf9d36a0c3bd58c90f463f91304174af29e909)

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued 5bcf9d36a0c3bd58c90f463f91304174af29e909 with parent fa521a4, future comparison URL.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5bcf9d36a0c3bd58c90f463f91304174af29e909): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This 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.

mean1rangecount2
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
1.0%[1.0%, 1.0%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Cycles

Results

This 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.

mean1rangecount2
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
3.9%[2.9%, 4.9%]2
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Footnotes

  1. the arithmetic mean of the percent change2

  2. number of relevant changes2

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 12, 2022
@oli-obk

Copy link
Copy Markdown
Contributor

I don't expect this to affect perfbot. We don't have runtime benchmarks for such changes, so you'll have to manually benchmark some examples

@Kobzol

Copy link
Copy Markdown
Member

This PR modifies the compiler code, not stdlib, so it should be visible in perfbot, or not? In any case, the changes look quite reasonable.

@oli-obk

Copy link
Copy Markdown
Contributor

Oh right. Still, these changes are not in hot paths. It's a good cleanup either way.

@bors r+ rollup

@bors

bors commented Sep 13, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 66211d8 has been approved by oli-obk

It is now in the queue for this repository.

@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 Sep 13, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Sep 13, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 13, 2022
…-obk
Avoid `Iterator::last`
Adapters like `Filter` and `Map` use the default implementation of `Iterator::last` which is not short-circuiting (and so does `core::str::Split`). The predicate function will be run for every single item of the underlying iterator. I hope that removing those calls to `last` results in slight performance improvements.
@Dylan-DPCDylan-DPC mentioned this pull request Sep 13, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2022
Rollup of 5 pull requests
Successful merges:
- rust-lang#101602 (Streamline `AttrAnnotatedTokenStream`)
- rust-lang#101690 (Avoid `Iterator::last`)
- rust-lang#101700 (A `SubstitutionPart` is not considered a deletion if it replaces nothing with nothing)
- rust-lang#101745 (Fix typo in concat_bytes documentation)
- rust-lang#101748 (rustdoc: remove redundant CSS `#source-sidebar, #sidebar-toggle`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit d5b86d5 into rust-lang:masterSep 13, 2022
@rustbotrustbot added this to the 1.65.0 milestone Sep 13, 2022
@kadiwa4
kadiwa4 deleted the avoid_iterator_last branch September 13, 2022 17:18
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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@kadiwa4@rust-highfive@leonardo-m@Kobzol@rust-timer@bors@oli-obk@rustbot