Skip to content

Rollup of 4 perf-sensitive pull requests - #166152

Merged
rust-bors[bot] merged 9 commits into
rust-lang:mainfrom
JonathanBrouwer:rollup-k1eoUpv
Nov 18, 2026
Merged

rust-bors[bot] merged 9 commits into
rust-lang:mainfrom
JonathanBrouwer:rollup-k1eoUpv

Conversation

@JonathanBrouwer

Copy link
Copy Markdown
Member

Successful merges:

r? @ghost

Create a similar rollup

nnethercote and others added 9 commits November 16, 2026 08:35
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>
>
> ![ai:0](https://github.com/jdonszelmann/0rwx.com/blob/main/static/50x50/AI-0-50x50.png?raw=true)
>
> </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
@rust-bors rust-bors Bot added the rollup A PR which is a rollup label Nov 18, 2026
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Nov 18, 2026
@JonathanBrouwer JonathanBrouwer changed the title Rollup of 4 pull requests Rollup of 4 perf-sensitive pull requests Nov 18, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member Author

@bors r+ p=5 force

Trying commonly failed jobs
@bors try jobs=dist-various-1,dist-various-2,test-various,test-x86_64-gnu-aux,test-x86_64-msvc-1,test-aarch64-apple-1,test-aarch64-apple-2,test-x86_64-mingw-1,test-i686-msvc,test-armhf-gnu,test-x86_64-gnu-llvm-22-3,test-aarch64-msvc-2

@rust-bors

rust-bors Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ca637b3 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Nov 18, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
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
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: c3bb646 (c3bb646b4cfbff66eb97224124b8721e9cfb7744)
Base parent: 6c587fd (6c587fd5a7f62ceb4fda4e19f0af26d2f9521ae6)

@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 18, 2026
@rust-bors

rust-bors Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: JonathanBrouwer
Duration: 3h 35m 31s
Pushing 65ce861 to main...

@rust-bors
rust-bors Bot merged commit 65ce861 into rust-lang:main Nov 18, 2026
16 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 18, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

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)

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (65ce861): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

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.0% [-15.7%, -0.2%] 147
Improvements ✅
(secondary)
-0.9% [-4.6%, -0.0%] 169
All ❌✅ (primary) -1.0% [-15.7%, -0.2%] 147

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.

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.7% [-2.2%, -1.2%] 2
Improvements ✅
(secondary)
-2.3% [-4.5%, -0.5%] 8
All ❌✅ (primary) -0.7% [-2.2%, 1.2%] 3

Cycles

Results (primary -3.3%, secondary -2.6%)

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.6%, 2.6%] 1
Regressions ❌
(secondary)
2.2% [0.4%, 5.0%] 4
Improvements ✅
(primary)
-4.3% [-8.2%, -2.4%] 6
Improvements ✅
(secondary)
-4.4% [-10.5%, -0.5%] 11
All ❌✅ (primary) -3.3% [-8.2%, 2.6%] 7

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

Bootstrap: 458.383s -> 458.82s (0.10%)
Artifact size: 405.23 MiB -> 405.35 MiB (0.03%)

@rust-bors

rust-bors Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#165396 Perf - Separate flag computation & intern functions per `Ty… 8bd646e2bba5d0b9a06a82b2e4d9302f763f58cd
(link)
#165774 Auto trait finder: Avoid recomputing ParamEnv if nothing … 89b1c4374f8d9dc9292a70f5bb48696adc0b5801
(link)
#165863 Avoid instantiating FnSig when not necessary 14824e259705414e153d3edfc9fa0b6bb0d96a0b
(link)
#166084 Avoid unnecessary LLVM passes when thin LTO buffer is null db947ef6a92902a294883e90cfd94f4d3ca26e73
(link)

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 $SHA $SHA $SHA..., or run @rust-timer triage all to benchmark all rollup members.

@JonathanBrouwer

Copy link
Copy Markdown
Member Author

@rust-timer triage all

@rust-timer

rust-timer commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator
Running triage with 52 benchmarks

Triage only executes the benchmarks on rollup members, that were changed significantly on the rollup.
For this rollup, these benchmarks are:

  • await-call-tree
  • bitmaps-3.2.1
  • bitmaps-3.2.1-new-solver
  • cargo-0.87.1
  • clap_derive-4.5.32
  • clap_derive-4.5.32-nll
  • coercions
  • cranelift-codegen-0.119.0
  • ctfe-stress-5
  • deeply-nested-multi
  • deeply-nested-multi-new-solver
  • derive
  • diesel-2.2.10
  • diesel-2.2.10-new-solver
  • enum-stress
  • eza-0.21.2
  • helloworld
  • helloworld-tiny
  • html5ever-0.31.0
  • html5ever-0.31.0-new-solver
  • hyper-1.6.0
  • image-0.25.6
  • issue-46449
  • issue-58319
  • issue-88862
  • large-workspace
  • nalgebra-0.33.0
  • nalgebra-0.33.0-new-solver
  • next-solver-stress
  • projection-caching
  • regex-automata-0.4.8
  • regression-31157
  • ripgrep-14.1.1
  • ripgrep-14.1.1-nll
  • ripgrep-14.1.1-tiny
  • serde-1.0.219
  • serde-1.0.219-new-solver
  • serde-1.0.219-nll
  • serde_derive-1.0.219
  • stm32f4-0.15.1
  • syn-2.0.101
  • syn-2.0.101-new-solver
  • token-stream-stress
  • tokio-1.53.1
  • typenum-1.18.0
  • typenum-1.18.0-new-solver
  • ucd
  • unicode-normalization-0.1.24
  • unify-linearly
  • wf-projection-stress-65510
  • wg-grammar
  • wg-grammar-new-solver

#165396 8bd646e Perf - Separate flag computation & intern functions per TyKind

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% [-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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. merged-by-bors This PR was explicitly merged by bors. rollup A PR which is a rollup 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.

7 participants