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

Inline FnOnce/FnMut/Fn shims once again #137907

Merged
merged 2 commits into from
Mar 5, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 3, 2025

This PR fixes the argument checking for extern "rust-call" ABI functions with a spread arg, which do no expect their arguments to be exploded from a tuple like closures do.

Secondly, it removes the hack that prevented them from being inlined. This results in more work done by the compiler, but it does end up allowing us to inline functions we didn't before.

Fixes #137901

@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, 2025
@compiler-errors
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 Mar 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

cc rust-lang#137901

r? `@ghost`
@bors
Copy link
Contributor

bors commented Mar 3, 2025

⌛ Trying commit 3be05c2 with merge 66b5f9d...

@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 3, 2025

⌛ Trying commit 2091084 with merge 633435e...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

cc rust-lang#137901

r? `@ghost`
@bors
Copy link
Contributor

bors commented Mar 3, 2025

☀️ Try build successful - checks-actions
Build commit: 633435e (633435edd7c1b4e80999da27eba46fd6726a55b5)

@rust-timer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

compiler-errors commented Mar 3, 2025

Previously, this ended up making things kinda slow in the compiler: #110833 (comment).

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…, r=<try>

[do not merge] Inliner experiment 2

cc rust-lang#137907 (comment)

r? `@ghost`
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (633435e): 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)
13.7% [0.5%, 59.3%] 5
Regressions ❌
(secondary)
0.7% [0.5%, 1.9%] 7
Improvements ✅
(primary)
-0.4% [-0.9%, -0.2%] 16
Improvements ✅
(secondary)
-0.8% [-3.4%, -0.2%] 24
All ❌✅ (primary) 3.0% [-0.9%, 59.3%] 21

Max RSS (memory usage)

Results (primary 0.4%, secondary 2.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)
8.7% [3.9%, 15.3%] 3
Regressions ❌
(secondary)
4.4% [2.6%, 6.3%] 2
Improvements ✅
(primary)
-3.1% [-4.8%, -1.7%] 7
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) 0.4% [-4.8%, 15.3%] 10

Cycles

Results (primary 12.8%, 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)
33.9% [5.9%, 61.9%] 2
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-1.3% [-2.1%, -0.8%] 3
Improvements ✅
(secondary)
-7.0% [-9.9%, -3.4%] 3
All ❌✅ (primary) 12.8% [-2.1%, 61.9%] 5

Binary size

Results (primary -0.1%, secondary -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)
0.2% [0.0%, 1.0%] 10
Regressions ❌
(secondary)
0.5% [0.2%, 1.1%] 4
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 66
Improvements ✅
(secondary)
-0.2% [-1.3%, -0.1%] 38
All ❌✅ (primary) -0.1% [-0.6%, 1.0%] 76

Bootstrap: missing data
Artifact size: 361.95 MiB -> 361.94 MiB (-0.00%)

@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, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…, r=<try>

[do not merge] Inliner experiment 2

cc rust-lang#137907 (comment)

r? `@ghost`
@Noratrieb
Copy link
Member

For the clap regression: I ran cachegrind and confirmed that yes, this is indeed all in LLVM (as the codegen split in rustc-perf already suggested). Give that this is incr-patched, it seems likely that this is because of a lack of CGU partitioning luck due to the extra inlining.
Given that that most other benchmarks are positive (even some incr-patched) I think that this can be merged despite this large regression. It does look like clap is at a local minimum here, but given that CGU partitioning is an inherently chaotic system, I don't think such local minima have to constrain our space here. It seems likely that if someone does future changes to CGU partitioning, the chaos will reshuffle and clap might get the perf back.
I haven't looked into serde_derive but I suspect it's the same.

But I think @saethlin would have a more informed opinion on this

@compiler-errors compiler-errors marked this pull request as ready for review March 3, 2025 20:25
@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@compiler-errors
Copy link
Member Author

r? saethlin or reassign

@compiler-errors
Copy link
Member Author

agh didn't mean to push that last commit

@saethlin
Copy link
Member

saethlin commented Mar 3, 2025

There is also no data for the runtime benchmarks.

@compiler-errors
Copy link
Member Author

Let me fix CI (there seems to be some platform-dependent inliner instability) then I can queue another perf run.

@compiler-errors
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 Mar 3, 2025
@bors
Copy link
Contributor

bors commented Mar 3, 2025

⌛ Trying commit d33946c with merge 76aedcd...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

This PR fixes the argument checking for `extern "rust-call"` ABI functions with a spread arg, which do no expect their arguments to be exploded from a tuple like closures do.

Secondly, it removes the hack that prevented them from being inlined. This results in more work done by the compiler, but it does end up allowing us to inline functions we didn't before.

Fixes rust-lang#137901
@saethlin
Copy link
Member

saethlin commented Mar 3, 2025

But I think @saethlin would have a more informed opinion on this

Slightly more informed. I think opt-incr-patched benchmarks do not deserve the same weight as the rest of the benchmark suite because our compilation pipeline very deeply does not support optimizations and incrementality at the same time. Maybe we could make it do that, but swings like this are an indicator that we haven't made the investment, not that this PR is bad.

I know I've pointed at CGU partitioning as the cause of this in the past, and I believe that's technically wrong so I just want to say this before it gets too widespread. The actual partitioning part of the algorithm is very stable to perturbations, what is unstable is the instantiation mode selection, which selects which Instances are partitioned explicitly vs lazily.

It would be pretty cool for these incr-patched benchmarks to identify the number of dirtied CGUs. I think that's basically the number of LLVM_module_codegen_emit_obj executions, which in this PR for clap jumps from 10 to 31. Of course figuring out why this edit now dirties 31 CGUs is harder problem.

Comment on lines 697 to +699
InstanceKind::Intrinsic(_) | InstanceKind::Virtual(..) => {
debug!("instance without MIR (intrinsic / virtual)");
return Err("implementation limitation");
return Err("implementation limitation -- cannot inline intrinsic");
Copy link
Member

Choose a reason for hiding this comment

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

Actually we can inline intrinsics, but we don't want to.

if tcx.has_attr(def_id, sym::rustc_intrinsic) {
// Intrinsic fallback bodies are always cross-crate inlineable.
// To ensure that the MIR inliner doesn't cluelessly try to inline fallback
// bodies even when the backend would implement something better, we stop
// the MIR inliner from ever inlining an intrinsic.
return true;
}

@saethlin
Copy link
Member

saethlin commented Mar 4, 2025

Phew, that inliner clause was something. Thank you so much for fixing this.

r=me when CI passes

@bors
Copy link
Contributor

bors commented Mar 4, 2025

☀️ Try build successful - checks-actions
Build commit: 76aedcd (76aedcdeb6b4edbc45a7ef7b705993bf0eb42b8d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (76aedcd): 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)
16.9% [0.5%, 59.2%] 4
Regressions ❌
(secondary)
0.6% [0.4%, 1.8%] 7
Improvements ✅
(primary)
-0.4% [-0.9%, -0.1%] 22
Improvements ✅
(secondary)
-0.7% [-3.6%, -0.2%] 30
All ❌✅ (primary) 2.3% [-0.9%, 59.2%] 26

Max RSS (memory usage)

Results (primary 0.6%, secondary 1.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)
8.4% [3.5%, 14.5%] 3
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-3.2% [-5.0%, -1.7%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [-5.0%, 14.5%] 9

Cycles

Results (primary 22.2%, secondary -1.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)
33.9% [5.8%, 61.9%] 2
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-2.4% [-3.6%, -1.0%] 3
All ❌✅ (primary) 22.2% [-1.0%, 61.9%] 3

Binary size

Results (primary -0.1%, secondary -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)
0.2% [0.0%, 1.0%] 10
Regressions ❌
(secondary)
0.5% [0.2%, 1.1%] 4
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 68
Improvements ✅
(secondary)
-0.2% [-1.3%, -0.1%] 38
All ❌✅ (primary) -0.1% [-0.6%, 1.0%] 78

Bootstrap: 773.808s -> 774.314s (0.07%)
Artifact size: 361.97 MiB -> 361.95 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 4, 2025
@compiler-errors
Copy link
Member Author

@bors r=saethlin rollup=never

@bors
Copy link
Contributor

bors commented Mar 4, 2025

📌 Commit d33946c has been approved by saethlin

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 Mar 4, 2025
@scottmcm
Copy link
Member

scottmcm commented Mar 5, 2025

Bumping this over my other never PRs since this affects how library PRs are written
@bors p=1

@bors
Copy link
Contributor

bors commented Mar 5, 2025

⌛ Testing commit d33946c with merge 30f168e...

@bors
Copy link
Contributor

bors commented Mar 5, 2025

☀️ Test successful - checks-actions
Approved by: saethlin
Pushing 30f168e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 5, 2025
@bors bors merged commit 30f168e into rust-lang:master Mar 5, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 5, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (30f168e): comparison URL.

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

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

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

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)
13.6% [0.4%, 59.2%] 5
Regressions ❌
(secondary)
0.6% [0.4%, 1.9%] 7
Improvements ✅
(primary)
-0.4% [-0.9%, -0.1%] 25
Improvements ✅
(secondary)
-0.7% [-3.4%, -0.1%] 41
All ❌✅ (primary) 2.0% [-0.9%, 59.2%] 30

Max RSS (memory usage)

Results (primary 2.9%, secondary 2.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)
4.3% [0.5%, 15.0%] 13
Regressions ❌
(secondary)
2.5% [0.7%, 4.6%] 59
Improvements ✅
(primary)
-3.4% [-4.7%, -2.7%] 3
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 2.9% [-4.7%, 15.0%] 16

Cycles

Results (primary 34.1%, secondary -0.7%)

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)
34.1% [6.2%, 62.0%] 2
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) 34.1% [6.2%, 62.0%] 2

Binary size

Results (primary -0.1%, secondary -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)
0.2% [0.0%, 0.9%] 10
Regressions ❌
(secondary)
0.5% [0.2%, 1.1%] 4
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 66
Improvements ✅
(secondary)
-0.2% [-1.3%, -0.1%] 38
All ❌✅ (primary) -0.1% [-0.6%, 0.9%] 76

Bootstrap: 775.73s -> 773.363s (-0.31%)
Artifact size: 362.10 MiB -> 362.14 MiB (0.01%)

@Kobzol
Copy link
Contributor

Kobzol commented Mar 11, 2025

Overall there are more wins than regressions, and this change should help optimizations. The single large regression is unlucky CGU scheduling on an optimized incremental build, which is not very common.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 11, 2025
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-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.

MIR inliner not inlining through is_some_and sometimes
10 participants