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

Simplify Vec using iter::repeat_n #104596

Closed
wants to merge 4 commits into from

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Nov 19, 2022

By using repeat_n instead of ExtendElement, we can delete a bunch more unsafe code from Vec.

All the codegen tests are passing (and I made one stricter to help be sure), so let's see if perf is also happy with it.

r? @ghost

Built atop #104435; will leave draft until I can rebase atop that.

Today it always copies it for *every* appended element, but one of those clones is avoidable.
By using `repeat_n` instead of `ExtendElement`, we can delete a bunch more `unsafe` code from `Vec.

All the codegen tests are passing (and I made one stricter to help be sure), so let's see if perf is also happy with it.
@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 19, 2022
@scottmcm
Copy link
Member Author

@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 19, 2022
@bors
Copy link
Contributor

bors commented Nov 19, 2022

⌛ Trying commit 50b394a with merge 30c97e84bdbff017290f6d12db34df2f225359a8...

@bors
Copy link
Contributor

bors commented Nov 19, 2022

☀️ Try build successful - checks-actions
Build commit: 30c97e84bdbff017290f6d12db34df2f225359a8 (30c97e84bdbff017290f6d12db34df2f225359a8)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (30c97e84bdbff017290f6d12db34df2f225359a8): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

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-review -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 0.7%] 24
Regressions ❌
(secondary)
2.3% [0.2%, 5.5%] 15
Improvements ✅
(primary)
-0.8% [-1.0%, -0.6%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-1.0%, 0.7%] 26

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.

mean range count
Regressions ❌
(primary)
1.8% [0.4%, 3.8%] 5
Regressions ❌
(secondary)
1.7% [1.2%, 2.5%] 3
Improvements ✅
(primary)
-4.6% [-4.6%, -4.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [-4.6%, 3.8%] 6

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.

mean range count
Regressions ❌
(primary)
0.8% [0.7%, 0.9%] 3
Regressions ❌
(secondary)
5.0% [4.5%, 5.8%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.3% [-5.3%, -5.3%] 1
All ❌✅ (primary) 0.8% [0.7%, 0.9%] 3

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 19, 2022
@the8472
Copy link
Member

the8472 commented Nov 19, 2022

I'm not sure if it's a good idea to remove this. There's untapped optimization potential in the current implementation. E.g. it could use the zero-value check that vec initialization already has and then use Allocator::grow_zeroed.

@scottmcm
Copy link
Member Author

@the8472 I agree that's a good thing to add, but I don't think it needs the ExtendWith trait, since we can't do that for ExtendFunc anyway. I could leave an private extend_element function without the trait and type, though, if you think that'd be helpful.

@scottmcm
Copy link
Member Author

@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 19, 2022
@bors
Copy link
Contributor

bors commented Nov 19, 2022

⌛ Trying commit 78f2356 with merge d6ba54d913266c13b4ddf2eaf8b1b9b023df4caa...

@bors
Copy link
Contributor

bors commented Nov 19, 2022

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d6ba54d913266c13b4ddf2eaf8b1b9b023df4caa): comparison URL.

Overall result: ❌ regressions - 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.

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-review -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.2%, 1.2%] 76
Regressions ❌
(secondary)
1.8% [0.2%, 6.6%] 30
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) 0.5% [0.2%, 1.2%] 76

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.

mean range count
Regressions ❌
(primary)
1.1% [0.4%, 2.4%] 6
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
-4.8% [-4.8%, -4.8%] 1
Improvements ✅
(secondary)
-3.7% [-5.3%, -2.1%] 2
All ❌✅ (primary) 0.3% [-4.8%, 2.4%] 7

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.

mean range count
Regressions ❌
(primary)
0.9% [0.8%, 1.0%] 6
Regressions ❌
(secondary)
2.5% [1.3%, 3.7%] 8
Improvements ✅
(primary)
-1.4% [-1.9%, -0.9%] 9
Improvements ✅
(secondary)
-2.8% [-5.2%, -2.1%] 13
All ❌✅ (primary) -0.5% [-1.9%, 1.0%] 15

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 20, 2022
@scottmcm
Copy link
Member Author

Curious -- arguably good on cycles, but clearly bad on instructions.

I guess I should do this in smaller pieces, if at all.

@scottmcm scottmcm closed this Nov 20, 2022
@scottmcm scottmcm deleted the simplify-vec-internals branch November 20, 2022 01:02
scottmcm added a commit to scottmcm/rust that referenced this pull request Nov 20, 2022
Repeating is `TrustedLen`, so we don't need another copy of [the `TrustedLen` specialization for `extend`](https://github.com/rust-lang/rust/blob/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/alloc/src/vec/spec_extend.rs#L27).

(This is a simpler version of rust-lang#104596, which tried to do too many things at once.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants