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

[perf experiments] Clone all MIR bodies #125025

Closed
wants to merge 5 commits into from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented May 11, 2024

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?

Based on this PR, it looks like the literal clone is cheap enough to be considered free, but running basically any MIR transform on the cloned MIR is a measurable slowdown. The hope here was that we could do optimizations on monomorphized MIR. I think ther eare two problems with that:

The first problem is this:

* NOTE: Simplify CFG will happily undo most of the work this pass does.

LLVM needs a certain structure around calls, which is generally wasteful in terms of the MIR that it takes to generate. We currently cope with this by creating the required structure at the end of the optimized_mir passes. This is very problematic, because the most obvious post-mono optimization is running something like SimplifyCfg to remove if true and if false and the resultant goto chains, but that deletes all the work of AddCallGuard, so now you need to run at least two post-mono MIR transforms.

The second problem is that naively monomorphizing the entire Body doesn't skip unreachable blocks. I tried adding some code that uses the same reachability analysis to skip dead code, but something subtle happens that causes one of our secondary benchmarks to regress a lot. That's this perf run: #125025 (comment). I never figured out what causes this slowdown. The later perf runs are me trying to figure out what that's from.

@rustbot
Copy link
Collaborator

rustbot commented May 11, 2024

r? @lcnr

rustbot has assigned @lcnr.
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2024
@saethlin
Copy link
Member Author

Oops, sorry about that.

@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 May 11, 2024
@saethlin saethlin 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. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 11, 2024
@bors
Copy link
Contributor

bors commented May 11, 2024

⌛ Trying commit bedbc3c with merge c0bcf54...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 11, 2024
[perf experiments] Clone all MIR bodies

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?
@bors
Copy link
Contributor

bors commented May 11, 2024

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

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

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

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

Binary size

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

Bootstrap: 673.703s -> 675.385s (0.25%)
Artifact size: 315.98 MiB -> 315.88 MiB (-0.03%)

@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 May 12, 2024
@bors
Copy link
Contributor

bors commented May 12, 2024

⌛ Trying commit 940cb4a with merge f0a6c88...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2024
[perf experiments] Clone all MIR bodies

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?
@bors
Copy link
Contributor

bors commented May 12, 2024

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f0a6c88): 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)
4.0% [4.0%, 4.0%] 1
Regressions ❌
(secondary)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.0% [4.0%, 4.0%] 1

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

Binary size

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

Bootstrap: 676.399s -> 675.548s (-0.13%)
Artifact size: 315.85 MiB -> 316.04 MiB (0.06%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 12, 2024
@RalfJung
Copy link
Member

RalfJung commented May 12, 2024

Hm... so maybe Miri should clone the body and apply the substitution once, rather than applying it on each statement? For hot loops that should help a lot. But for big functions where we only run a small part of the code, less so.

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

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

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.6% [0.2%, 1.6%] 205
Regressions ❌
(secondary)
0.8% [0.1%, 18.7%] 82
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [0.2%, 1.6%] 205

Max RSS (memory usage)

Results (primary -2.3%, 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)
- - 0
Regressions ❌
(secondary)
2.9% [2.4%, 3.5%] 2
Improvements ✅
(primary)
-2.3% [-4.6%, -0.7%] 4
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) -2.3% [-4.6%, -0.7%] 4

Cycles

Results (primary 1.1%, secondary -1.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)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
14.7% [14.7%, 14.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-5.9%, -2.2%] 7
All ❌✅ (primary) 1.1% [1.1%, 1.1%] 1

Binary size

Results (primary -0.4%, secondary -0.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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.7%, -0.1%] 65
Improvements ✅
(secondary)
-0.2% [-0.5%, -0.1%] 18
All ❌✅ (primary) -0.4% [-0.7%, -0.1%] 65

Bootstrap: 671.52s -> 677.804s (0.94%)
Artifact size: 320.35 MiB -> 927.58 MiB (189.55%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 13, 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 14, 2024
@bors
Copy link
Contributor

bors commented Jun 14, 2024

⌛ Trying commit c49fd8f with merge 7da58b9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2024
[perf experiments] Clone all MIR bodies

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 14, 2024

💔 Test failed - checks-actions

@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 15, 2024
[perf experiments] Clone all MIR bodies

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?
@bors
Copy link
Contributor

bors commented Jun 15, 2024

⌛ Trying commit 17184f8 with merge e881ea0...

@bors
Copy link
Contributor

bors commented Jun 15, 2024

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

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

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%] 168
Regressions ❌
(secondary)
0.7% [0.1%, 18.5%] 73
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.2%, 1.6%] 168

Max RSS (memory usage)

Results (primary -3.2%, secondary 2.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)
- - 0
Regressions ❌
(secondary)
2.5% [2.1%, 3.2%] 3
Improvements ✅
(primary)
-3.2% [-4.4%, -2.6%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.2% [-4.4%, -2.6%] 4

Cycles

Results (secondary 3.0%)

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.5% [2.7%, 14.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.8%, -2.3%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.4%, secondary -0.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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.7%, -0.1%] 65
Improvements ✅
(secondary)
-0.2% [-0.5%, -0.1%] 18
All ❌✅ (primary) -0.4% [-0.7%, -0.1%] 65

Bootstrap: 671.997s -> 675.131s (0.47%)
Artifact size: 320.43 MiB -> 923.77 MiB (188.29%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 15, 2024
@saethlin
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Jun 15, 2024

⌛ Trying commit 740c135 with merge b3d0a6a...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 15, 2024
[perf experiments] Clone all MIR bodies

We keep saying things like cloning all the MIR would be expensive, but... how expensive actually?
@bors
Copy link
Contributor

bors commented Jun 16, 2024

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

@saethlin
Copy link
Member Author

I've updated the PR description with my conclusions from these experiments.

@saethlin saethlin closed this Jul 16, 2024
@saethlin saethlin deleted the clone-your-body branch July 16, 2024 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants