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

Apply "polymorphization at home" to RawVec #126793

Merged
merged 7 commits into from
Aug 12, 2024
Merged

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Jun 21, 2024

The idea here is to move all the logic in RawVec into functions with explicit size and alignment parameters. This should eliminate all the fussing about how tweaking RawVec code produces large swings in compile times.

This uncovered rust-lang/rust-clippy#12979, so I've modified the relevant test in a way that tries to preserve the spirit of the test without tripping the ICE.

@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 Jun 21, 2024
@rust-log-analyzer

This comment has been minimized.

@saethlin
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 Jun 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 21, 2024
Monomorphize RawVec

The idea here is to move all the logic in RawVec into functions with explicit size and alignment parameters. This should eliminate all the fussing about how tweaking RawVec code produces large swings in compile times.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Jun 21, 2024

⌛ Trying commit ec16141 with merge 7646794...

@rust-log-analyzer

This comment has been minimized.

@@ -462,85 +657,26 @@ impl<T, A: Allocator> RawVec<T, A> {
// of the code that doesn't depend on `T` as possible is in functions that
// are non-generic over `T`.
fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
const { assert!(mem::size_of::<T>() % mem::align_of::<T>() == 0) };
Copy link
Member

Choose a reason for hiding this comment

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

nit: is this checking anything? That's definitionally true for all types, AFAIK...

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷 This was in the original code. There's also a wrong comment in current_memory about types where size != stride, such types do not exist in Rust.

Copy link
Member

@the8472 the8472 Jun 21, 2024

Choose a reason for hiding this comment

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

#83706 added this check by going through Layout::array
#107167 partially undid it since it previously caused a small perf regression but left the const assert in its place to move the check to compile time

Copy link
Member Author

Choose a reason for hiding this comment

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

I've deleted all these const assertions. I don't know if that was the right move here? I'm not opposed to adding it by some other means, but it seems a bit silly to have an assertion if it's true by definition.

}

struct MonoRawVec<A: Allocator = Global> {
ptr: Unique<u8>,
Copy link
Member

Choose a reason for hiding this comment

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

YMMV: Maybe make yourself an opaque type (like the one in

extern "C" {
/// Opaque type for accessing vtables.
///
/// Private implementation detail of `DynMetadata::size_of` etc.
/// There is conceptually not actually any Abstract Machine memory behind this pointer.
type VTable;
}
) to make sure you don't accidentally use the u8-ness of this anywhere?

@bors
Copy link
Contributor

bors commented Jun 21, 2024

☀️ Try build successful - checks-actions
Build commit: 7646794 (764679442556a000f69f7c7f3f3b0080d4dae76a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7646794): 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

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)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-5.0%, -0.2%] 82
Improvements ✅
(secondary)
-1.8% [-4.4%, -0.3%] 11
All ❌✅ (primary) -1.3% [-5.0%, 2.9%] 83

Max RSS (memory usage)

Results (primary -0.6%, secondary -4.9%)

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)
4.4% [1.4%, 7.4%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.1% [-8.4%, -2.2%] 7
Improvements ✅
(secondary)
-4.9% [-5.5%, -4.3%] 2
All ❌✅ (primary) -0.6% [-8.4%, 7.4%] 12

Cycles

Results (primary -2.2%, secondary -3.2%)

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)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-4.5%, -1.2%] 34
Improvements ✅
(secondary)
-3.2% [-4.7%, -2.6%] 5
All ❌✅ (primary) -2.2% [-4.5%, 2.6%] 35

Binary size

Results (primary -2.0%, secondary -0.5%)

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.1%, 2.5%] 11
Regressions ❌
(secondary)
0.1% [0.1%, 0.2%] 4
Improvements ✅
(primary)
-2.3% [-7.5%, -0.0%] 105
Improvements ✅
(secondary)
-0.6% [-4.6%, -0.0%] 47
All ❌✅ (primary) -2.0% [-7.5%, 2.5%] 116

Bootstrap: 694.089s -> 690.601s (-0.50%)
Artifact size: 326.85 MiB -> 327.00 MiB (0.05%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 21, 2024
@Kobzol
Copy link
Contributor

Kobzol commented Jun 21, 2024

Woah, this looks awesome! Truly a "we have polymorphization at home" moment.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 22, 2024
@saethlin saethlin changed the title Monomorphize RawVec Apply "polymorphization at home" to RawVec Jun 22, 2024
@saethlin
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 Jun 22, 2024
@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 11, 2024
Apply "polymorphization at home" to RawVec

The idea here is to move all the logic in RawVec into functions with explicit size and alignment parameters. This should eliminate all the fussing about how tweaking RawVec code produces large swings in compile times.

This uncovered rust-lang/rust-clippy#12979, so I've modified the relevant test in a way that tries to preserve the spirit of the test without tripping the ICE.

try-job: x86_64-msvc
@bors
Copy link
Contributor

bors commented Aug 11, 2024

⌛ Testing commit 28a8301 with merge ba33d7b...

@bors
Copy link
Contributor

bors commented Aug 12, 2024

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing ba33d7b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 12, 2024
@bors
Copy link
Contributor

bors commented Aug 12, 2024

👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward

@saethlin
Copy link
Member Author

rust-lang/homu#75

@bors r=scottmcm

@bors
Copy link
Contributor

bors commented Aug 12, 2024

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Aug 12, 2024

📌 Commit 28a8301 has been approved by scottmcm

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 12, 2024

⌛ Testing commit 28a8301 with merge 13f8a57...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ba33d7b): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.6%] 98
Regressions ❌
(secondary)
0.4% [0.1%, 1.2%] 125
Improvements ✅
(primary)
-1.0% [-3.5%, -0.2%] 51
Improvements ✅
(secondary)
-1.3% [-2.9%, -0.3%] 13
All ❌✅ (primary) -0.0% [-3.5%, 1.6%] 149

Max RSS (memory usage)

Results (primary -0.5%, secondary 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)
3.1% [1.8%, 4.4%] 8
Regressions ❌
(secondary)
2.3% [1.0%, 4.9%] 4
Improvements ✅
(primary)
-3.7% [-7.0%, -0.9%] 9
Improvements ✅
(secondary)
-2.8% [-4.1%, -1.4%] 2
All ❌✅ (primary) -0.5% [-7.0%, 4.4%] 17

Cycles

Results (primary -1.3%, secondary 0.5%)

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.5% [1.1%, 2.5%] 4
Regressions ❌
(secondary)
2.3% [1.6%, 2.7%] 6
Improvements ✅
(primary)
-2.0% [-5.8%, -1.0%] 17
Improvements ✅
(secondary)
-2.2% [-3.0%, -1.4%] 4
All ❌✅ (primary) -1.3% [-5.8%, 2.5%] 21

Binary size

Results (primary -1.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)
0.8% [0.0%, 3.6%] 33
Regressions ❌
(secondary)
0.2% [0.1%, 3.4%] 38
Improvements ✅
(primary)
-2.5% [-6.8%, -0.1%] 81
Improvements ✅
(secondary)
-1.4% [-4.5%, -0.1%] 16
All ❌✅ (primary) -1.6% [-6.8%, 3.6%] 114

Bootstrap: 756.29s -> 754.361s (-0.26%)
Artifact size: 341.47 MiB -> 341.52 MiB (0.02%)

@bors
Copy link
Contributor

bors commented Aug 12, 2024

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing 13f8a57 to master...

@bors bors merged commit 13f8a57 into rust-lang:master Aug 12, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 12, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (13f8a57): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.5%] 89
Regressions ❌
(secondary)
0.4% [0.1%, 1.3%] 96
Improvements ✅
(primary)
-1.1% [-3.8%, -0.2%] 54
Improvements ✅
(secondary)
-1.2% [-2.9%, -0.3%] 13
All ❌✅ (primary) -0.1% [-3.8%, 1.5%] 143

Max RSS (memory usage)

Results (primary -0.8%, secondary 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)
3.4% [2.4%, 4.8%] 6
Regressions ❌
(secondary)
3.4% [2.0%, 5.7%] 3
Improvements ✅
(primary)
-3.6% [-6.0%, -1.8%] 9
Improvements ✅
(secondary)
-2.6% [-4.2%, -1.5%] 3
All ❌✅ (primary) -0.8% [-6.0%, 4.8%] 15

Cycles

Results (primary -1.1%, secondary -1.2%)

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.7% [0.8%, 2.1%] 6
Regressions ❌
(secondary)
6.1% [6.1%, 6.1%] 1
Improvements ✅
(primary)
-1.7% [-3.5%, -0.8%] 25
Improvements ✅
(secondary)
-2.6% [-3.7%, -1.7%] 5
All ❌✅ (primary) -1.1% [-3.5%, 2.1%] 31

Binary size

Results (primary -1.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)
0.8% [0.0%, 3.6%] 33
Regressions ❌
(secondary)
0.2% [0.1%, 3.4%] 38
Improvements ✅
(primary)
-2.5% [-6.8%, -0.1%] 82
Improvements ✅
(secondary)
-1.4% [-4.5%, -0.1%] 16
All ❌✅ (primary) -1.6% [-6.8%, 3.6%] 115

Bootstrap: 755.478s -> 752.51s (-0.39%)
Artifact size: 341.47 MiB -> 339.31 MiB (-0.63%)

@rylev
Copy link
Member

rylev commented Aug 13, 2024

Given the comments here, I think this regression can be marked triaged.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Aug 13, 2024
@saethlin saethlin deleted the mono-rawvec branch August 13, 2024 21:30
@Mark-Simulacrum
Copy link
Member

Seconding, but also noting that this seems to have been a good memory usage improvement (probably due to smaller code footprint?) that held up as the week progressed. Good work!

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 23, 2024
…try>

Enable Alignment::new_unchecked precondition check

Similar to what happened with rust-lang#126556, I think this has become palatable since rust-lang#126793.

r? `@ghost`
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 24, 2024
Apply "polymorphization at home" to RawVec

The idea here is to move all the logic in RawVec into functions with explicit size and alignment parameters. This should eliminate all the fussing about how tweaking RawVec code produces large swings in compile times.

This uncovered rust-lang/rust-clippy#12979, so I've modified the relevant test in a way that tries to preserve the spirit of the test without tripping the ICE.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…orkingjubilee

Enable Alignment::new_unchecked precondition check

Similar to what happened with rust-lang#126556, I think this has become palatable since rust-lang#126793.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…orkingjubilee

Enable Alignment::new_unchecked precondition check

Similar to what happened with rust-lang#126556, I think this has become palatable since rust-lang#126793.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 26, 2024
…ilee

Enable Alignment::new_unchecked precondition check

Similar to what happened with rust-lang/rust#126556, I think this has become palatable since rust-lang/rust#126793.
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.