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

Use iter::repeat_n to implement Vec::extend_with #133662

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paolobarbolini
Copy link
Contributor

@paolobarbolini paolobarbolini commented Nov 30, 2024

This replaces the Vec::extend_with manual implementation, which is used by Vec::resize and Vec SpecFromElem, with iter::repeat_n.

I've compared the codegen output between:

  1. the current Vec::resize impl
  2. this branch
  3. this branch + Safer implementation of RepeatN #130887

3 gives the closest codegen output to 1, with some output improvements. 2 doesn't look good: https://rust.godbolt.org/z/Yrc83EhjY.
May also help #120050?


WARNING: DO NOT MERGE - in order to run the perf run in #133662 (comment) this PR currently also contains commits from #130887

@rustbot
Copy link
Collaborator

rustbot commented Nov 30, 2024

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 30, 2024
@joboet
Copy link
Member

joboet commented Nov 30, 2024

Let's see what effect this has in the compiler!
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Nov 30, 2024

⌛ Trying commit 4bf7072 with merge 243c5cc...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2024
…epeatn, r=<try>

Use `iter::repeat_n` to implement `Vec::extend_with`

This replaces the `Vec::extend_with` manual implementation, which is used by `Vec::resize` and `Vec` `SpecFromElem`, with `iter::repeat_n`.

I've compared the codegen output between:

1. the current `Vec::resize` impl
2. this branch
3. this branch + rust-lang#130887

3 gives the closest codegen output to 1, with some output improvements. 2 doesn't look good: https://rust.godbolt.org/z/Yrc83EhjY.
May also help rust-lang#120050?
@Noratrieb
Copy link
Member

given that this branch doesn't look good without #130887, let's block it on that.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2024
@bors
Copy link
Contributor

bors commented Nov 30, 2024

☀️ Try build successful - checks-actions
Build commit: 243c5cc (243c5cc6905efbdf778394d96f4b83701962964f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (243c5cc): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.1%, 0.7%] 16
Regressions ❌
(secondary)
0.4% [0.1%, 0.6%] 9
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-1.3% [-1.8%, -0.5%] 8
All ❌✅ (primary) 0.3% [-0.9%, 0.7%] 17

Max RSS (memory usage)

Results (primary 0.1%)

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.

mean range count
Regressions ❌
(primary)
5.6% [0.9%, 11.4%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-8.1% [-11.1%, -5.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-11.1%, 11.4%] 5

Cycles

Results (secondary -2.1%)

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.4%)

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.

mean range count
Regressions ❌
(primary)
0.5% [0.0%, 1.3%] 43
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 7
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [-0.2%, 1.3%] 50

Bootstrap: 773.805s -> 774.205s (0.05%)
Artifact size: 332.32 MiB -> 331.64 MiB (-0.20%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 30, 2024
@paolobarbolini
Copy link
Contributor Author

paolobarbolini commented Dec 1, 2024

Could we do another perf run? I've cherry-picked the commit from #130887 since, at least via Compiler Explorer, the codegen looked better

@joboet
Copy link
Member

joboet commented Dec 1, 2024

Sure!
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Dec 1, 2024

⌛ Trying commit b080e18 with merge 78d5ed4...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 1, 2024
…epeatn, r=<try>

Use `iter::repeat_n` to implement `Vec::extend_with`

This replaces the `Vec::extend_with` manual implementation, which is used by `Vec::resize` and `Vec` `SpecFromElem`, with `iter::repeat_n`.

I've compared the codegen output between:

1. the current `Vec::resize` impl
2. this branch
3. this branch + rust-lang#130887

3 gives the closest codegen output to 1, with some output improvements. 2 doesn't look good: https://rust.godbolt.org/z/Yrc83EhjY.
May also help rust-lang#120050?

---

WARNING: DO NOT MERGE - in order to run the perf run in rust-lang#133662 (comment) this PR currently also contains commits from rust-lang#130887
@bors
Copy link
Contributor

bors commented Dec 1, 2024

☀️ Try build successful - checks-actions
Build commit: 78d5ed4 (78d5ed40d7c459a7e5ea4cb6bea9918a493a800f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (78d5ed4): comparison URL.

Overall result: ❌ regressions - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.4% [0.1%, 0.7%] 17
Regressions ❌
(secondary)
1.3% [0.1%, 3.2%] 16
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.1%, 0.7%] 17

Max RSS (memory usage)

Results (primary -5.6%, secondary 0.3%)

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.

mean range count
Regressions ❌
(primary)
5.3% [5.3%, 5.3%] 1
Regressions ❌
(secondary)
1.5% [1.0%, 1.8%] 3
Improvements ✅
(primary)
-11.1% [-15.5%, -6.8%] 2
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) -5.6% [-15.5%, 5.3%] 3

Cycles

Results (primary -1.5%, secondary 35.1%)

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.

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
35.1% [33.0%, 39.1%] 6
Improvements ✅
(primary)
-4.0% [-4.0%, -4.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.5% [-4.0%, 0.9%] 2

Binary size

Results (primary 0.6%)

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.

mean range count
Regressions ❌
(primary)
0.7% [0.1%, 1.7%] 33
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 9
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [-0.2%, 1.7%] 42

Bootstrap: 767.632s -> 769.266s (0.21%)
Artifact size: 332.19 MiB -> 332.16 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 1, 2024
@paolobarbolini
Copy link
Contributor Author

Looking at performance data borrow checking time in the Cycles benchmark for wg-grammar is the main culprit. I'm confused why that is.

The fact that this also fixes #120050 makes these changes still worth it to me.

@paolobarbolini
Copy link
Contributor Author

@joboet @scottmcm Do you think the combination of #130887 + this PR, plus the fact it could also fix #120050, could have a chance of working out? I'm not too sure how to interpret the benchmarks and if there's a way of fixing the wg-grammar Cycles regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants