Skip to content

Canonicalization cleanups - #165537

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
nnethercote:canonicalization-micro-opts
Nov 11, 2026
Merged

rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
nnethercote:canonicalization-micro-opts

Conversation

@nnethercote

@nnethercote nnethercote commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

I saw some moderate perf improvements locally with these changes but on CI they had no effect. Maybe due to PGO? Most of the changes are actually refactorings which I think are still worth merging.

r? @ShoyuVanilla

@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 Nov 6, 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 6, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 6, 2026
@rust-bors

rust-bors Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: bad7b83 (bad7b83c86b45f6cbb0ecdce3417ef833cc8c4f6)
Base parent: 249c1e4 (249c1e4e31111b54ad2483cfd4cea06c7020c653)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (bad7b83): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (primary 2.4%, secondary 3.1%)

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

mean range count
Regressions ❌
(primary)
2.4% [2.4%, 2.4%] 1
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.4% [2.4%, 2.4%] 1

Cycles

Results (primary -2.0%)

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)
- - 0
All ❌✅ (primary) -2.0% [-2.0%, -2.0%] 1

Binary size

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

Bootstrap: 481.055s -> 482.135s (0.22%)
Artifact size: 406.29 MiB -> 406.33 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2026
Currently we build it even when the `NEEDS_CANONICAL` test fails.
It has a single call site. This will enable an optimization in the next
commit.
Do a `NEEDS_CANONICAL` check on the entire input. We already have such
checks on the relevant parts, but this lets us entirely avoid building a
`Canonicalizer` when the check fails.
It causes it to intern or not intern. Instead we can just let the
call site that passes in `true` do its own interning.
@nnethercote
nnethercote force-pushed the canonicalization-micro-opts branch from aca70bd to d7064be Compare November 10, 2026 04:41
@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: some of the ideas in this PR came from LLM analysis. I wrote the code and text myself.

@nnethercote nnethercote changed the title Canonicalization micro-optimizations Canonicalization cleanups Nov 10, 2026
@nnethercote
nnethercote marked this pull request as ready for review November 10, 2026 21:32
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

ShoyuVanilla is currently at their maximum review capacity.
They may take a while to respond.

@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 10, 2026
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

ShoyuVanilla is currently at their maximum review capacity.
They may take a while to respond.

@nnethercote

nnethercote commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Of the five commits:

  1. Avoid building Canonicalizer unnecessarily in canonicalize_response
  2. Inline and remove canonicalize_param_env
  3. Early return in canonicalize_input
  4. Remove bool arg from do_env_and_make_rest
  5. Factor out repetitive code

Commits 1 and 3 are the perf optimizations. We could choose to remove them because they have no effect on CI, but they did have a small effect for me locally so we could keep them for non-PGO platforms. Commits 2, 4, and 5 are refactorings that I think are worth merging regardless.

@ShoyuVanilla ShoyuVanilla left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Commit 1 and 3 also look good to me regardless of the perf 😄
@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d7064be has been approved by ShoyuVanilla

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 11, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Rollup of 9 pull requests

Successful merges:

 - #165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #165750 (Wrap proc-macro `EscapeError` enum into a struct)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
 - #165021 (In irrefutable patterns, the FieldPat is skipped, which means the name: field is not printed)
 - #165537 (Canonicalization cleanups)
 - #165772 (Remove unnecessary mut from HirIdValidator::check_nested_id)
 - #165779 (make improper_ctypes accept `x87_f80`)
 - #165780 (std: map more errno values to ErrorKind on Hermit)
@rust-bors
rust-bors Bot merged commit e599087 into rust-lang:main Nov 11, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Rollup merge of #165537 - nnethercote:canonicalization-micro-opts, r=ShoyuVanilla

Canonicalization cleanups

I saw some moderate perf improvements locally with these changes but on CI they had no effect. Maybe due to PGO? Most of the changes are actually refactorings which I think are still worth merging.

r? @ShoyuVanilla
@nnethercote
nnethercote deleted the canonicalization-micro-opts branch November 11, 2026 07:42
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 13, 2026
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - rust-lang/rust#165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - rust-lang/rust#165750 (Wrap proc-macro `EscapeError` enum into a struct)
 - rust-lang/rust#164218 (Tweak private re-export errors to point at correct span and have more context)
 - rust-lang/rust#165021 (In irrefutable patterns, the FieldPat is skipped, which means the name: field is not printed)
 - rust-lang/rust#165537 (Canonicalization cleanups)
 - rust-lang/rust#165772 (Remove unnecessary mut from HirIdValidator::check_nested_id)
 - rust-lang/rust#165779 (make improper_ctypes accept `x87_f80`)
 - rust-lang/rust#165780 (std: map more errno values to ErrorKind on Hermit)
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. 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.

4 participants