Skip to content

Optimize DroplessArena arena allocation #108693

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

Merged
merged 3 commits into from
Aug 16, 2023
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 3, 2023

This optimizes DroplessArena allocation by always ensuring that it is aligned to usize and adding grow_and_alloc and grow_and_alloc_rawfunctions which both grow and allocate, reducing code size.

BenchmarkBeforeAfter
TimeTime%
🟣 clap:check1.6968s1.6887s -0.48%
🟣 hyper:check0.2552s0.2551s -0.03%
🟣 regex:check0.9613s0.9553s -0.62%
🟣 syn:check1.5402s1.5374s -0.18%
🟣 syntex_syntax:check5.9175s5.8813s -0.61%
Total10.3710s10.3178s -0.51%
Summary1.0000s0.9962s -0.38%

@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2023

r? @cjgillot

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 3, 2023
@matthiaskrgr
Copy link
Member

@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 Mar 3, 2023
@bors
Copy link
Collaborator

bors commented Mar 3, 2023

⌛ Trying commit a3fc36e383c59629274d74b6ac103dc90e96660c with merge 96f98934793755c7ae42a2e0a9ccc49289135001...

@bors
Copy link
Collaborator

bors commented Mar 3, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (96f98934793755c7ae42a2e0a9ccc49289135001): 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-perf +perf-regression

Warning ⚠: The following benchmark(s) failed to build:

  • webrender-2022

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
Regressions ❌
(secondary)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
-0.6% [-0.7%, -0.6%] 3
Improvements ✅
(secondary)
-0.5% [-1.0%, -0.2%] 6
All ❌✅ (primary) -0.6% [-0.7%, -0.6%] 3

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)
- - 0
Regressions ❌
(secondary)
3.3% [0.9%, 7.6%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-3.8%, -1.4%] 11
All ❌✅ (primary) - - 0

Cycles

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 3, 2023
@cjgillot
Copy link
Contributor

cjgillot commented Mar 3, 2023

Any idea what broke the benchmark?

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 3, 2023

No. It kind of looks like a problem with rustc-perf. Maybe it's non-deterministic?

@Zoxc Zoxc force-pushed the arena-opt-funcs branch from b7fa43d to 3e34eca Compare March 3, 2023 11:20
@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 3, 2023

You could give this another perf run to see if it reproduces. I also added another optimization bringing instructions for allocating an usize from 8 down to 6.

@cjgillot
Copy link
Contributor

cjgillot commented Mar 3, 2023

@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 Mar 3, 2023
@bors
Copy link
Collaborator

bors commented Mar 3, 2023

⌛ Trying commit 3e34eca9a4f22f4277c78d7aac5ea72ed5156724 with merge 48a8ae2628df7f3ccd0a365bd173203710f305ac...

@bors
Copy link
Collaborator

bors commented Mar 4, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (48a8ae2628df7f3ccd0a365bd173203710f305ac): 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-perf +perf-regression

Warning ⚠: The following benchmark(s) failed to build:

  • webrender-2022

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.2% [0.2%, 0.3%] 9
Regressions ❌
(secondary)
0.9% [0.2%, 1.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 9

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)
- - 0
Regressions ❌
(secondary)
8.0% [8.0%, 8.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-4.0%, -1.1%] 11
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.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 4, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 4, 2023

This could use another perf run to see if more aggressive inlining helps recover the bootstrap improvement.

@cjgillot
Copy link
Contributor

cjgillot commented Mar 4, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@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 May 28, 2023
@bors
Copy link
Collaborator

bors commented May 28, 2023

⌛ Trying commit deef40780126946106eaed6734d680cc6489798d with merge 6a923fd31c77214782a0cea705ad8fd9b5b4204f...

@bors
Copy link
Collaborator

bors commented May 28, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6a923fd31c77214782a0cea705ad8fd9b5b4204f): 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-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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.5% [1.4%, 4.5%] 16
Improvements ✅
(primary)
-2.0% [-2.9%, -1.0%] 2
Improvements ✅
(secondary)
-3.6% [-4.6%, -2.8%] 5
All ❌✅ (primary) -2.0% [-2.9%, -1.0%] 2

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 647.057s -> 645.932s (-0.17%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 28, 2023
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

A few comments. Did you reach a decision on https://github.com/rust-lang/rust/pull/108693/files#r1125632892?

}

#[inline(always)]
fn align(val: usize, align: usize) -> usize {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn align(val: usize, align: usize) -> usize {
fn align_up(val: usize, align: usize) -> usize {

For symmetry with align_down.

// Align the end to DROPLESS_ALIGNMENT
let end = align_down(chunk.end().addr(), DROPLESS_ALIGNMENT);
// Make sure we don't go past `start`
let end = cmp::max(chunk.start().addr(), end);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it even possible to go past start? Should this be a debug_assert instead?
What if start is unsufficiently aligned?

Comment on lines +455 to +464
#[inline(never)]
#[cold]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? It just calls another inline(never) method with a constant argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It keeps the passing of the constant argument out of the hot path.


let new_end = end.checked_sub(bytes)? & !(align - 1);
let new_end = align_down(end.checked_sub(bytes)?, layout.align());
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a line comment explaining why new_end is at least aligned on DROPLESS_ALIGNMENT?

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 2, 2023
@Zoxc Zoxc force-pushed the arena-opt-funcs branch from deef407 to 6f86591 Compare August 14, 2023 19:30
@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 14, 2023

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2023
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 16, 2023

📌 Commit 6f86591 has been approved by cjgillot

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 Aug 16, 2023
@bors
Copy link
Collaborator

bors commented Aug 16, 2023

⌛ Testing commit 6f86591 with merge 07438b0...

@bors
Copy link
Collaborator

bors commented Aug 16, 2023

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 07438b0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 16, 2023
@bors bors merged commit 07438b0 into rust-lang:master Aug 16, 2023
@rustbot rustbot added this to the 1.73.0 milestone Aug 16, 2023
@Zoxc Zoxc deleted the arena-opt-funcs branch August 17, 2023 00:02
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (07438b0): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -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
Regressions ❌
(secondary)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

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)
- - 0
Regressions ❌
(secondary)
2.7% [0.8%, 5.9%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.8% [-12.1%, -1.2%] 7
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 635.158s -> 635.21s (0.01%)
Artifact size: 346.86 MiB -> 346.72 MiB (-0.04%)

@Zoxc Zoxc mentioned this pull request Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants