Skip to content

[perf] Reuse existing trait reference instead of recreating it. - #160539

Open
obi1kenobi wants to merge 1 commit into
rust-lang:mainfrom
obi1kenobi:pg/normalizes-to-reuse-ref
Open

[perf] Reuse existing trait reference instead of recreating it.#160539
obi1kenobi wants to merge 1 commit into
rust-lang:mainfrom
obi1kenobi:pg/normalizes-to-reuse-ref

Conversation

@obi1kenobi

@obi1kenobi obi1kenobi commented Aug 5, 2026

Copy link
Copy Markdown
Member

Effectively, do one step of common subexpression elimination, manually. We can reuse the existing interned reference made a few lines prior, without needing to recreate it.

r? @lcnr

AI disclosure: The optimization opportunity here was discovered as part of a systematic probe for missed optimizations using a combination of both traditional and AI tools. The code here was initially prototyped and vetted by AI tools, followed by additional manual work. I stand behind the quality of the code I'm submitting, and I vouch it's as good or better than if no AI tools were in the loop.

@rustbot rustbot added 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 5, 2026
@Zalathar

Zalathar commented Aug 5, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 5, 2026
[perf] Reuse existing trait reference instead of recreating it.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 5, 2026
@rust-bors

rust-bors Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4a90c30 (4a90c30649a165543d68cdd23bfae7a76e5bd4a8)
Base parent: 1ed2df6 (1ed2df61a19042f231709eb05d032ae9e2cb2084)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4a90c30): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

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.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@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.2% [0.2%, 0.3%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.1% [-7.5%, -0.1%] 10
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 4

Max RSS (memory usage)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-4.9%, -0.4%] 6
All ❌✅ (primary) - - 0

Cycles

Results (primary 1.5%, secondary -0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.5% [0.6%, 2.7%] 6
Regressions ❌
(secondary)
1.5% [0.5%, 3.8%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.5% [-3.6%, -0.4%] 11
All ❌✅ (primary) 1.5% [0.6%, 2.7%] 6

Binary size

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

Bootstrap: 489.825s -> 491.303s (0.30%)
Artifact size: 391.14 MiB -> 391.36 MiB (0.06%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 5, 2026
@lcnr

lcnr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

any reason this is still a draft? r=me after

@obi1kenobi
obi1kenobi marked this pull request as ready for review August 6, 2026 07:18
@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 Aug 6, 2026
@lcnr

lcnr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

next-solver perf is absolutely wonderful, big fan

@bors r+ rollup=never

@rust-bors

rust-bors Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8d8e996 has been approved by lcnr

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 Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants