Repository navigation
Rollup of 4 perf-sensitive pull requests - #166152
Conversation
It's left over from an earlier cleanup.
`LLVMRustOptimize` runs three passes when `NeedThinLTOBufferPasses` is true: `CanonicalizeAliasesPass`, `NameAnonGlobalPass` and `AssignGUIDPass`. These passes are only needed when the module's bitcode or summary will be written. This commit updates how `NeedThinLTOBufferPasses` is initialized in `LLVMRustOptimize`; instead of being initialized as always true, it's now only true if a thin LTO buffer is provided. (Subsequent existing code in the function may change `NeedThinLTOBufferPasses` to false.) Avoiding the unnecessary passes improves compile times a little, e.g. on debug builds (which are `O0` + `PreLinkNoLTO`). That requires a change to the passes added by `LLVMRustModuleSerialize`, because it currently relies on `LLVMRustOptimize` having run `CanonicalizeAliasesPass` and `NameAnonGlobalPass`, and this is no longer true in some cases such as `--emit=llvm-bc`. The passes are idempotent so it doesn't hurt if they are run twice in other cases. Non-LTO `--emit=llvm-ir,asm` output changes in two ways: unnamed globals stay unnamed (or are named `__unnamed` by LLVM) instead of being named `anon` (this requires updating some tests) and `!guid` metadata disappears.
In various places we call `fn_sig`, which is expensive because it instantiates the signature, but then only look at the ABI or the safety, which don't require the instantiation. This commit introduces `fn_sig_abi` and `fn_sig_safety` which are alternatives that skip instantiation. In `check_instance_abi` the commit also changes `instance.ty(...)` to `tcx.type_of(...)` to avoid a second unnecessary instantiation path.
…, r=nnethercote Perf - Separate flag computation & intern functions per `TyKind` Create a separate function for interning each `TyKind` and an individual flags computation function. Doing this means that we can avoid a match statement that previously existed when computing flags which improves perf; rust-lang#165396 (comment) Separately there might be some wins with splitting out the `InternedSet`'s (see 'Original Description' below) however, in my view, there is enough of a benefit with this relatively simple change that modifying the `InternedSet`'s could be a separate exploration. **Edit:** My original write up for the PR is below. However what this PR has become and what the original intention was has drifted sufficiently that writing a new description made the most sense to me. <details> <summary> Original Description</summary> Create an `InternedSet` per `TyKind` variant; this is something I discussed with @lqd & @lcnr separately, both thought it was a reasonable idea. I believe the speedup comes from no longer having to check the `TyKind` on every call to `intern_ty(...)` when computing flags. This saves several function calls and branches. As such I also had to create separate `flags()` functions to get the flags for a `TyKind` so we don't have to do a match on the kind. ### LLM usage; TLDR; I prototyped a PR as I knew a lot of the implementation would be boilerplate, ran perf to see if it was worth following up on, @lqd & @lcnr thought it looked promising. Hence I've now opened this PR which is my work borrowing parts from the prototype. **Longer version** The idea is mine and I discussed it with @lcnr before doing any work, we also decided using an LLM to explore if the idea was worth pursing seemed reasonable. I used an LLM to completely vibe code the [first commit of a prototype-y PR](rust-lang@1b6b590) to verify the idea, which I then reviewed, and subsequently [ran perf, things looked decent](rust-lang#165136 (comment)). The other commits in that prototype PR were me, not an LLM, trying to effectively create the below idea; ```rust fn compute_flags<const K: ty::TyKind<'tcx>() { const match K.kind() { // } } ``` Which I subsequently abandoned as I couldn't get it to work even when turning on a bunch of experimental features. I appreciate that might be me doing things wrong. I tried this as to me this idea seems to scream for compile-time evaluation as we can know the `TyKind` at compile time. This PR has been written by me borrowing bits from my original LLM/James collaborative prototype. </details> r? @nnethercote
…=fmease Auto trait finder: Avoid recomputing `ParamEnv` if nothing changed r? @fmease > [!NOTE] > <table> > <tr><td> > >  > > </td><td> > > [I've not used an LLM for any part of this PR, or any other PR I make. This includes any related work like research.](https://0rwx.com/.) > > </td></tr> > </table>
…Sig, r=bjorn3 Avoid instantiating `FnSig` when not necessary In various places we call `fn_sig`, which is expensive because it instantiates the signature, but then only look at the ABI or the safety, which don't require the instantiation. This commit introduces `fn_sig_abi` and `fn_sig_safety` which are alternatives that skip instantiation. In `check_instance_abi` the commit also changes `instance.ty(...)` to `tcx.type_of(...)` to avoid a second unnecessary instantiation path. r? @bjorn3
…s, r=nikic Avoid unnecessary LLVM passes when thin LTO buffer is null `LLVMRustOptimize` runs three passes when `NeedThinLTOBufferPasses` is true: `CanonicalizeAliasesPass`, `NameAnonGlobalPass` and `AssignGUIDPass`. These passes are only needed when the module's bitcode or summary will be written. This commit updates how `NeedThinLTOBufferPasses` is initialized in `LLVMRustOptimize`; instead of being initialized as always true, it's now only true if a thin LTO buffer is provided. (Subsequent existing code in the function may change `NeedThinLTOBufferPasses` to false.) Avoiding the unnecessary passes improves compile times a little, e.g. on debug builds (which are `O0` + `PreLinkNoLTO`). That requires a change to the passes added by `LLVMRustModuleSerialize`, because it currently relies on `LLVMRustOptimize` having run `CanonicalizeAliasesPass` and `NameAnonGlobalPass`, and this is no longer true in some cases such as `--emit=llvm-bc`. The passes are idempotent so it doesn't hurt if they are run twice in other cases. Non-LTO `--emit=llvm-ir,asm` output changes in two ways: unnamed globals stay unnamed (or are named `__unnamed` by LLVM) instead of being named `anon` (this requires updating some tests) and `!guid` metadata disappears. r? @nikic
Rollup of 4 perf-sensitive pull requests try-job: dist-various-1 try-job: dist-various-2 try-job: test-various try-job: test-x86_64-gnu-aux try-job: test-x86_64-msvc-1 try-job: test-aarch64-apple-1 try-job: test-aarch64-apple-2 try-job: test-x86_64-mingw-1 try-job: test-i686-msvc try-job: test-armhf-gnu try-job: test-x86_64-gnu-llvm-22-3 try-job: test-aarch64-msvc-2
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
A job failed! Check out the build log: (web) (plain enhanced) (plain) Click to see the possible cause of the failure (guessed by this bot) |
|
Finished benchmarking commit (65ce861): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.7%, secondary -2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -3.3%, secondary -2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -1.0%, secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 458.383s -> 458.82s (0.10%) |
|
📌 Perf builds for each rolled up PR:
parent commit: 412be32a6a In the case of a perf regression, run the following command with the SHAs of each PR you suspect might be the cause: |
|
@rust-timer triage all |
Running triage with 52 benchmarksTriage only executes the benchmarks on rollup members, that were changed significantly on the rollup.
#165396 8bd646e Perf - Separate flag computation & intern functions per
|
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-0.5% | [-1.0%, -0.2%] | 115 |
| Improvements ✅ (secondary) |
-0.7% | [-3.3%, -0.1%] | 134 |
| All ❌✅ (primary) | -0.5% | [-1.0%, -0.2%] | 115 |
Max RSS (memory usage)
Results (primary -1.3%, secondary -0.6%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-1.3% | [-1.3%, -1.3%] | 1 |
| Improvements ✅ (secondary) |
-0.6% | [-0.6%, -0.6%] | 1 |
| All ❌✅ (primary) | -1.3% | [-1.3%, -1.3%] | 1 |
Cycles
Results (secondary -1.3%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
5.7% | [5.7%, 5.7%] | 1 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-2.4% | [-3.1%, -0.6%] | 6 |
| All ❌✅ (primary) | - | - | 0 |
Binary size
This perf run didn't have relevant results for this metric.
#165774 89b1c43 Auto trait finder: Avoid recomputing ParamEnv if nothing changed
Instruction count
Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-1.9% | [-15.3%, -0.2%] | 29 |
| Improvements ✅ (secondary) |
-1.4% | [-3.3%, -0.3%] | 8 |
| All ❌✅ (primary) | -1.9% | [-15.3%, -0.2%] | 29 |
Max RSS (memory usage)
Results (secondary -1.1%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-1.1% | [-1.3%, -0.9%] | 3 |
| All ❌✅ (primary) | - | - | 0 |
Cycles
Results (primary -4.7%, secondary -1.1%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-4.7% | [-8.7%, -2.2%] | 5 |
| Improvements ✅ (secondary) |
-1.1% | [-1.7%, -0.5%] | 2 |
| All ❌✅ (primary) | -4.7% | [-8.7%, -2.2%] | 5 |
Binary size
This perf run didn't have relevant results for this metric.
#165863 14824e2 Avoid instantiating FnSig when not necessary
Instruction count
Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-0.3% | [-0.5%, -0.2%] | 64 |
| Improvements ✅ (secondary) |
-0.3% | [-0.5%, -0.1%] | 35 |
| All ❌✅ (primary) | -0.3% | [-0.5%, -0.2%] | 64 |
Max RSS (memory usage)
Results (primary -0.8%, secondary -0.6%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
1.2% | [1.2%, 1.2%] | 1 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-1.8% | [-2.4%, -1.2%] | 2 |
| Improvements ✅ (secondary) |
-0.6% | [-0.8%, -0.4%] | 8 |
| All ❌✅ (primary) | -0.8% | [-2.4%, 1.2%] | 3 |
Cycles
Results (primary 2.6%, secondary 1.7%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
2.6% | [2.0%, 3.1%] | 2 |
| Regressions ❌ (secondary) |
2.1% | [0.4%, 5.0%] | 5 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-0.5% | [-0.5%, -0.5%] | 1 |
| All ❌✅ (primary) | 2.6% | [2.0%, 3.1%] | 2 |
Binary size
This perf run didn't have relevant results for this metric.
#166084 db947ef Avoid unnecessary LLVM passes when thin LTO buffer is null
Instruction count
Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-0.5% | [-0.7%, -0.2%] | 27 |
| Improvements ✅ (secondary) |
-1.0% | [-4.6%, -0.2%] | 19 |
| All ❌✅ (primary) | -0.5% | [-0.7%, -0.2%] | 27 |
Max RSS (memory usage)
Results (primary -1.2%, secondary -2.5%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-1.2% | [-1.2%, -1.2%] | 1 |
| Improvements ✅ (secondary) |
-2.5% | [-4.8%, -0.5%] | 8 |
| All ❌✅ (primary) | -1.2% | [-1.2%, -1.2%] | 1 |
Cycles
Results (secondary -5.4%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
0.4% | [0.4%, 0.4%] | 1 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-6.6% | [-10.5%, -2.4%] | 5 |
| All ❌✅ (primary) | - | - | 0 |
Binary size
Results (primary -1.0%, secondary -1.7%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
- | - | 0 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-1.0% | [-2.8%, -0.3%] | 67 |
| Improvements ✅ (secondary) |
-1.7% | [-9.0%, -0.2%] | 35 |
| All ❌✅ (primary) | -1.0% | [-2.8%, -0.3%] | 67 |
Successful merges:
TyKind#165396 (Perf - Separate flag computation & intern functions perTyKind)ParamEnvif nothing changed #165774 (Auto trait finder: Avoid recomputingParamEnvif nothing changed)FnSigwhen not necessary #165863 (Avoid instantiatingFnSigwhen not necessary)r? @ghost
Create a similar rollup