Skip to content

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

Open
train-dev-admin wants to merge 2 commits into
rust-lang:mainfrom
train-dev-admin:issue-166410-fix
Open

train-dev-admin wants to merge 2 commits 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

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
Comment thread compiler/rustc_lint/src/builtin.rs Outdated
}

// 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 thread compiler/rustc_lint/src/builtin.rs Outdated
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
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.

This branch has not been deployed

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Addressing perf regression from DUPLICATE_PARAMETER_NAMES lint

6 participants