Skip to content
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

Avoid Iterator::last #101690

Merged
merged 1 commit into from
Sep 13, 2022
Merged

Avoid Iterator::last #101690

merged 1 commit into from
Sep 13, 2022

Conversation

kadiwa4
Copy link
Contributor

@kadiwa4 kadiwa4 commented Sep 11, 2022

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.

@rustbot rustbot 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
Collaborator

r? @oli-obk

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

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 11, 2022
@rust-highfive rust-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

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
Contributor Author

kadiwa4 commented Sep 11, 2022

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

@Kobzol
Copy link
Contributor

Kobzol commented Sep 12, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

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

bors commented Sep 12, 2022

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

@bors
Copy link
Contributor

bors commented Sep 12, 2022

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

@rust-timer
Copy link
Collaborator

Queued 5bcf9d36a0c3bd58c90f463f91304174af29e909 with parent fa521a4, future comparison URL.

@rust-timer
Copy link
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.

mean1 range count2
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.

mean1 range count2
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 change 2

  2. number of relevant changes 2

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

oli-obk commented Sep 13, 2022

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
Contributor

Kobzol commented Sep 13, 2022

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
Contributor

oli-obk commented Sep 13, 2022

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

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 13, 2022

📌 Commit 66211d8 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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-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.
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:master Sep 13, 2022
@rustbot rustbot 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant 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