Skip to content

perf: avoid cloning associated items in empty_line_after#17135

Merged
Jarcho merged 1 commit into
rust-lang:masterfrom
xmakro:perf/empty-line-after-clone
Jun 5, 2026
Merged

perf: avoid cloning associated items in empty_line_after#17135
Jarcho merged 1 commit into
rust-lang:masterfrom
xmakro:perf/empty-line-after-clone

Conversation

@xmakro

@xmakro xmakro commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

empty_line_after's check_impl_item and check_trait_item converted every associated item into an ItemKind with item.kind.clone().into(), only to read its description string. The clone deep-copies the whole associated item, including function bodies, for each impl and trait item.

This reads the description directly from the AssocItemKind and passes the module's first-item id explicitly, so no ItemKind is constructed.

As part of this, I refactored the stored item kind from a description string into a small enum (ItemKindDescr). This is to avoid silent drift of str labels causing issues later on.

Instruction counts via valgrind --tool=callgrind (sum of clippy-driver Ir over a workspace re-lint), master vs this change:

crate master this PR change
serde 3,361,589,306 3,312,393,958 -1.46%
syn 2,115,732,491 2,106,118,839 -0.45%
wasmi 12,471,489,259 12,419,942,932 -0.41%
ripgrep 1,319,851,434 1,314,547,652 -0.40%
regex 816,516,564 814,654,422 -0.23%

changelog: none

@samueltardieu samueltardieu added the G-performance-project Goal: For issues and PRs related to the Clippy Performance Project label Jun 2, 2026
@xmakro xmakro force-pushed the perf/empty-line-after-clone branch from e1982d7 to 754ca96 Compare June 2, 2026 15:51
@xmakro xmakro marked this pull request as ready for review June 2, 2026 16:12
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 2, 2026
@rustbot

rustbot commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

Comment thread clippy_lints/src/empty_line_after.rs Outdated
@xmakro xmakro force-pushed the perf/empty-line-after-clone branch from 754ca96 to 4a2388c Compare June 5, 2026 17:20

@Jarcho Jarcho left a comment

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.

Thank you for finding/fixing various perf issues.

View changes since this review

@Jarcho Jarcho added this pull request to the merge queue Jun 5, 2026
Merged via the queue into rust-lang:master with commit 5a50f03 Jun 5, 2026
13 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

G-performance-project Goal: For issues and PRs related to the Clippy Performance Project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants