Skip to content

rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters - #166492

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
train-dev-admin:issue-166410-fix
Nov 26, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
train-dev-admin:issue-166410-fix

Conversation

@train-dev-admin

@train-dev-admin train-dev-admin commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Fixes #166410
Slowdown came from the lint in #165366 and showed up on externs and libc

Skip checking functions with fewer than 2 parameters.
Use a stack-allocated SmallVec instead of FxHashMap for small parameters lists.

Compare (Symbol, SyntaxContext) directly to avoid calling Ident::normalize_to_macro_rules()

The warnings are unchanged, I ran tests/ui/lint/duplicate-parameter-names.rs,
but looks like we need to do perf again: time regression on externs and libc should be less.

…ted_parameters

Skip checking functions with fewer than 2 parameters.

Use a stack-allocated SmallVec instead of FxHashMap for small parameters lists

Compare (Symbol, SyntaxContext) directly to avoid calling Ident::normalize_to_macro_rules()
@rustbot rustbot added 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 24, 2026
@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @wesleywiser (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 21 candidates

@JonathanBrouwer

Copy link
Copy Markdown
Member

r? me

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 24, 2026
rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters
}

// 16 bytes per entry (Symbol: 4B, SyntaxContext: 4B, Span: 8B) -> 128B on stack
let mut seen: SmallVec<[(Symbol, SyntaxContext, Span); 8]> = SmallVec::new();

@JonathanBrouwer JonathanBrouwer Nov 24, 2026 •

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.

This does have O(n^2) behaviour, but if you're running into that there are probably bigger problems

View changes since the review

@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: dccab3d (dccab3db509e9610ab796ec9fdd9bb547a2c70a2)
Base parent: 058c701 (058c701055c4b6f60f622d616afc0349911c38c3)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (dccab3d): comparison URL.

Overall result: ✅ improvements - no action needed

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

@bors rollup=iffy 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.2% [-0.2%, -0.2%] 3
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.2%] 8
All ❌✅ (primary) -0.2% [-0.2%, -0.2%] 3

Max RSS (memory usage)

Results (primary -3.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)
-3.1% [-3.1%, -3.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.1% [-3.1%, -3.1%] 1

Cycles

Results (primary -2.0%, secondary 2.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)
2.2% [2.2%, 2.2%] 1
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: 462.461s -> 470.678s (1.78%)
Artifact size: 405.65 MiB -> 405.64 MiB (-0.00%)

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

Copy link
Copy Markdown
Contributor

Nice, this doesn't recover the whole regression, but it's positive.

Comment on lines +790 to +791
(name == ident.name && prev_ctxt == ctxt).then_some(span)
}) {

@panstromek panstromek Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you want try improving this a bit more, I'd try to specialize it even more against the emit path - the lint almost never fires, and ctxt is almost always the same for a single function definition:

e.g. avoid normalize_to_macro_rules call on the main path, only store Symbol in the vec and compare only those during normal path, and when there's a match, lookup the ctxt and span back in the params again to confirm the ctxt and emit the lint.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@panstromek I hope I understand correct and new commit is exact what we need here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, let's try it out ;)

@panstromek

panstromek commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

There's a lot of things in the queue, we only need check results, so let's do that

@bors try @rust-timer queue profiles=Check

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

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 25, 2026
rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters
@rust-bors

rust-bors Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 52239fa (52239faae4f95424a871fbcfdd87132c0dce7182)
Base parent: 62bb1f5 (62bb1f56341b538ddfef5800fcceeb249893a43d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (52239fa): comparison URL.

Overall result: ✅ improvements - 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

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
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 462.136s -> 463.156s (0.22%)
Artifact size: 405.63 MiB -> 405.62 MiB (-0.00%)

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

Copy link
Copy Markdown
Contributor

This looks better, but only marginally, it might even be the same. libc result fell below significance threshold for some reason. That's probably some changes in main, because the result is almost the same. Full results (including non-relevant) are much greener than the previous run.

I think this is ok like this. @JonathanBrouwer Do you have some opinions? Feel free to r+ if not.

@JonathanBrouwer

JonathanBrouwer commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

I'd prefer to drop the second commit, it makes the code significantly more complicated for a -0.02% perf improvement, which could very well be noise.

(If I understand correctly, dropping the second commit returns the state to as it was when the first benchmark run happened.)

@rustbot author

r=me,panstromek after that

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@train-dev-admin

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@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 26, 2026
@panstromek

Copy link
Copy Markdown
Contributor

@bors r=panstromek,JonathanBrouwer

@rust-bors

rust-bors Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 322d31a has been tentatively approved by panstromek,JonathanBrouwer

It will be put into the queue for this repository once PR CI succeeds.

@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 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 26, 2026
…r=panstromek,JonathanBrouwer

rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters

Fixes rust-lang#166410
Slowdown came from the lint in rust-lang#165366 and showed up on `externs` and `libc`

Skip checking functions with fewer than 2 parameters.
Use a stack-allocated `SmallVec` instead of `FxHashMap` for small parameters lists.

Compare `(Symbol, SyntaxContext)` directly to avoid calling `Ident::normalize_to_macro_rules()`

The warnings are unchanged, I ran tests/ui/lint/duplicate-parameter-names.rs,
but looks like we need to do perf again: time regression on `externs` and `libc` should be less.
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #165489 (Add two extra early return checks to `is_recursive_terminator`)
 - #166248 (Make terminator not optional in BasicBlockData)
 - #166264 (Perf: Improve looking up previously scanned items in dead-code)
 - #166492 (rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters)
@rust-bors
rust-bors Bot merged commit 6174e2e into rust-lang:main Nov 26, 2026
29 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Rollup merge of #166492 - train-dev-admin:issue-166410-fix, r=panstromek,JonathanBrouwer

rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters

Fixes #166410
Slowdown came from the lint in #165366 and showed up on `externs` and `libc`

Skip checking functions with fewer than 2 parameters.
Use a stack-allocated `SmallVec` instead of `FxHashMap` for small parameters lists.

Compare `(Symbol, SyntaxContext)` directly to avoid calling `Ident::normalize_to_macro_rules()`

The warnings are unchanged, I ran tests/ui/lint/duplicate-parameter-names.rs,
but looks like we need to do perf again: time regression on `externs` and `libc` should be less.
@train-dev-admin
train-dev-admin deleted the issue-166410-fix branch November 26, 2026 23:01
@rust-timer

Copy link
Copy Markdown

Note

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

Finished benchmarking commit (a00ff46): 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.2% [-0.2%, -0.2%] 2
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 3
All ❌✅ (primary) -0.2% [-0.2%, -0.2%] 2

Max RSS (memory usage)

Results (primary -2.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)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.1% [-2.1%, -2.1%] 1

Cycles

Results (primary -2.4%, 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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-2.9%, -1.7%] 8
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) -2.4% [-2.9%, -1.7%] 8

Binary size

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

Artifact size: 405.62 MiB -> 405.60 MiB (-0.01%)

mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 27, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - rust-lang/rust#165489 (Add two extra early return checks to `is_recursive_terminator`)
 - rust-lang/rust#166248 (Make terminator not optional in BasicBlockData)
 - rust-lang/rust#166264 (Perf: Improve looking up previously scanned items in dead-code)
 - rust-lang/rust#166492 (rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters)
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.

Addressing perf regression from DUPLICATE_PARAMETER_NAMES lint

6 participants