Skip to content

Avoid instantiating FnSig when not necessary - #165863

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:avoid-instantiating-FnSig
Nov 18, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:avoid-instantiating-FnSig

Conversation

@nnethercote

@nnethercote nnethercote commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

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

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 12, 2026
@nnethercote

Copy link
Copy Markdown
Contributor 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 Nov 12, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
Avoid instantiating `FnSig` when not necessary
@rust-bors

rust-bors Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 15c8031 (15c8031dc8d8bb8da526299cf9bb3b3a89471372)
Base parent: b4fe65c (b4fe65c19d1bb6e720c843086b785493c453028d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (15c8031): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf -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)
-0.3% [-0.5%, -0.2%] 49
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.2%] 28
All ❌✅ (primary) -0.3% [-0.5%, -0.2%] 49

Max RSS (memory usage)

Results (primary 0.4%, 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)
5.2% [5.2%, 5.2%] 1
Regressions ❌
(secondary)
5.4% [3.8%, 7.1%] 2
Improvements ✅
(primary)
-2.0% [-2.1%, -2.0%] 2
Improvements ✅
(secondary)
-6.9% [-6.9%, -6.9%] 1
All ❌✅ (primary) 0.4% [-2.1%, 5.2%] 3

Cycles

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

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)
-2.0% [-2.0%, -2.0%] 1
Improvements ✅
(secondary)
-11.2% [-18.7%, -3.7%] 2
All ❌✅ (primary) -2.0% [-2.0%, -2.0%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 482.212s -> 481.954s (-0.05%)
Artifact size: 406.08 MiB -> 406.08 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 12, 2026
@rust-bors

This comment has been minimized.

@nnethercote
nnethercote force-pushed the avoid-instantiating-FnSig branch from 4d5b1d2 to 9c20e78 Compare November 12, 2026 22:03
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 12, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: this PR involve LLM analysis of profiles. I wrote the code and text myself.

@nnethercote
nnethercote marked this pull request as ready for review November 12, 2026 22:11
@rustbot

rustbot commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 12, 2026
Comment thread compiler/rustc_hir_typeck/src/callee.rs Resolved
It's left over from an earlier cleanup.
@nnethercote
nnethercote force-pushed the avoid-instantiating-FnSig branch from 9c20e78 to 4e22b4e Compare November 15, 2026 21:40
@rustbot

rustbot commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nnethercote

Copy link
Copy Markdown
Contributor Author

I fixed the "njn:" comments. Should be ready to go now.

Comment thread compiler/rustc_type_ir/src/ty_kind.rs Resolved
@nnethercote
nnethercote force-pushed the avoid-instantiating-FnSig branch from 4e22b4e to cfbe932 Compare November 16, 2026 22:30
@nnethercote

Copy link
Copy Markdown
Contributor Author

I addressed the two latest suggestions.

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.
@nnethercote
nnethercote force-pushed the avoid-instantiating-FnSig branch from cfbe932 to 5465832 Compare November 18, 2026 04:23
@bjorn3

bjorn3 commented Nov 18, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5465832 has been approved by bjorn3

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
@JonathanBrouwer

Copy link
Copy Markdown
Member

Creating a perf-sensitive rollup
@bors rollup=iffy

rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #165396 (Perf - Separate flag computation & intern functions per `TyKind`)
 - #165774 (Auto trait finder: Avoid recomputing `ParamEnv` if nothing changed)
 - #165863 (Avoid instantiating `FnSig` when not necessary)
 - #166084 (Avoid unnecessary LLVM passes when thin LTO buffer is null)
@rust-bors
rust-bors Bot merged commit 5510b38 into rust-lang:main Nov 18, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 18, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
Rollup merge of #165863 - nnethercote:avoid-instantiating-FnSig, 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
@nnethercote
nnethercote deleted the avoid-instantiating-FnSig branch November 18, 2026 22:02
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (14824e2): 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)
-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.

Artifact size: 405.23 MiB -> 405.27 MiB (0.01%)

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

Labels

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.

5 participants