Skip to content

create fast path for attributes created in builtin macro expansions - #164260

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:generated_attrs
Oct 25, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:generated_attrs

Conversation

@mejrs

@mejrs mejrs commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

View all comments

Emitting attributes in rustc_builtin_macros involves creating an ast::Attribute and token trees, just to parse that into a parsed attribute almost immediately. This PR sidesteps that by creating a new ast::Attribute variant that does not do this. I've taken care to only do this for the derive and test macros, so that they never re-enter the parser.

This results in some moderate performance gains. It'll also take away almost all of the regressions in #164217 (comment) (see #164281 (comment) for a perf run of this and that PR stacked)

r? @nnethercote

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Oct 13, 2026
@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member 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 Oct 13, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 13, 2026
create fast path for attributes created in derive expansions
@rust-log-analyzer

This comment has been minimized.

@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

@bors cancel

@rust-bors

rust-bors Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

❗ There is currently no auto build in progress on this PR.

Hint: There is a pending try build on this PR. Maybe you meant to cancel it? You can do that using @bors try cancel.

@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

@bors try cancel

@rust-bors

rust-bors Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run @bors try and bors will cancel the previous build automatically.

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Oct 13, 2026
@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 13, 2026
create fast path for attributes created in derive expansions
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 88e073e (88e073e9b84eab1e63c7cd966216841f2284fa1f)
Base parent: 91e426a (91e426a0518d5bb3672330c5238ccda6fd26fb54)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (88e073e): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-1.1%, -0.1%] 74
Improvements ✅
(secondary)
-1.3% [-3.8%, -0.2%] 26
All ❌✅ (primary) -0.4% [-1.1%, -0.1%] 74

Max RSS (memory usage)

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

Cycles

Results (primary -1.5%, secondary -3.9%)

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

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
3.8% [3.8%, 3.8%] 1
Improvements ✅
(primary)
-2.5% [-3.2%, -1.6%] 4
Improvements ✅
(secondary)
-5.0% [-6.9%, -3.2%] 7
All ❌✅ (primary) -1.5% [-3.2%, 2.3%] 5

Binary size

Results (primary 0.0%, secondary 0.1%)

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

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.1%] 9
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.1%] 9

Bootstrap: 489.812s -> 488.427s (-0.28%)
Artifact size: 406.88 MiB -> 406.97 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 13, 2026
@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member 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 Oct 13, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 13, 2026
create fast path for attributes created in derive expansions
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer 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.

Like the idea, love the performance.
Some comments tho :)

View changes since this review

Comment thread compiler/rustc_builtin_macros/src/deriving/default.rs
DocComment(CommentKind, Symbol),

/// A macro generated attribute inserted by a builtin macro.
Generated(GeneratedAttr),

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.

I'd really like to see the AttrKind::Synthetic and AttrKind::Generated be merged.
They're basically the same concept. I have no strong preferences about the naming

I saw @nnethercote proposed this in #164260 (comment) as well, but I didn't see this addressed.

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.

They're a little different: synthetic ones cannot be written by hand and cannot be pretty-printed, while generated ones can (in both cases). IMO this is probably enough to justify keeping them separate.

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.

I'd say the way they're generated is indeed different, and they need a different path in pretty printing (every variant is already handled individually there anyways so that's fine), but they basically behave the same. I don't really see the advantage to keeping them separate, and the disadvantage is more code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd prefer the compiler to crash if they re-enter the parser somehow, rather than be silently swallowed like the trace attributes are.

@JonathanBrouwer JonathanBrouwer Oct 25, 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.

I agree that that's desirable. I think you can still relatively easily make it work, it would be one extra match where the trace attributes are allowed, and a wildcard arm is unreachable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think there's enough difference between them to justify having different enum variants. I'd rather this isn't an implicit thing, and having different variants/types makes for a good place to put this documentation

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.

Since you both seem to agree that keeping them separate is better lets do that.
I'm not entirely convinced it's worth it, but don't feel strongly enough to block this PR on this.

Comment thread compiler/rustc_ast/src/ast.rs Outdated
@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 Oct 25, 2026
Comment thread compiler/rustc_ast/src/ast.rs Outdated
@rustbot

rustbot commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JonathanBrouwer JonathanBrouwer 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.

@bors r=JonathanBrouwer,nnethercote

Thanks! :3
The perf improvement makes me very happy

View changes since this review

@rust-bors

rust-bors Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit db2155b has been tentatively approved by JonathanBrouwer,nnethercote

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r=JonathanBrouwer,nnethercote rollup=iffy force
Creating a rollup of perf-sensitive PRs

@rust-bors

rust-bors Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit db2155b has been approved by JonathanBrouwer,nnethercote

It is now in the queue for this repository.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 25, 2026
…rouwer,nnethercote

create fast path for attributes created in builtin macro expansions

Emitting attributes in rustc_builtin_macros involves creating an `ast::Attribute` and token trees, just to parse that into a parsed attribute almost immediately. This PR sidesteps that by creating a new `ast::Attribute` variant that does not do this. I've taken care to only do this for the derive and test macros, so that they never re-enter the parser.

This results in some moderate performance gains. It'll also take away almost all of the regressions in rust-lang#164217 (comment) (see rust-lang#164281 (comment) for a perf run of this and that PR stacked)

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 3 perf-sensitive pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 25, 2026
…rouwer,nnethercote

create fast path for attributes created in builtin macro expansions

Emitting attributes in rustc_builtin_macros involves creating an `ast::Attribute` and token trees, just to parse that into a parsed attribute almost immediately. This PR sidesteps that by creating a new `ast::Attribute` variant that does not do this. I've taken care to only do this for the derive and test macros, so that they never re-enter the parser.

This results in some moderate performance gains. It'll also take away almost all of the regressions in rust-lang#164217 (comment) (see rust-lang#164281 (comment) for a perf run of this and that PR stacked)

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)
 - #164929 (Revert "rustc_codegen_gcc subtree update")

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
@rust-bors
rust-bors Bot merged commit bab8741 into rust-lang:main Oct 25, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
Rollup merge of #164260 - mejrs:generated_attrs, r=JonathanBrouwer,nnethercote

create fast path for attributes created in builtin macro expansions

Emitting attributes in rustc_builtin_macros involves creating an `ast::Attribute` and token trees, just to parse that into a parsed attribute almost immediately. This PR sidesteps that by creating a new `ast::Attribute` variant that does not do this. I've taken care to only do this for the derive and test macros, so that they never re-enter the parser.

This results in some moderate performance gains. It'll also take away almost all of the regressions in #164217 (comment) (see #164281 (comment) for a perf run of this and that PR stacked)

r? @nnethercote
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

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

Finished benchmarking commit (5d7c38d): 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.4% [-1.3%, -0.1%] 76
Improvements ✅
(secondary)
-1.3% [-3.9%, -0.2%] 26
All ❌✅ (primary) -0.4% [-1.3%, -0.1%] 76

Max RSS (memory usage)

Results (primary 0.4%, secondary 1.1%)

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

mean range count
Regressions ❌
(primary)
0.9% [0.4%, 2.0%] 12
Regressions ❌
(secondary)
1.3% [0.5%, 4.2%] 8
Improvements ✅
(primary)
-1.3% [-2.9%, -0.5%] 4
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) 0.4% [-2.9%, 2.0%] 16

Cycles

Results (primary -0.6%, secondary -1.9%)

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

mean range count
Regressions ❌
(primary)
0.5% [0.4%, 0.5%] 5
Regressions ❌
(secondary)
1.2% [0.5%, 2.7%] 4
Improvements ✅
(primary)
-1.0% [-2.1%, -0.4%] 17
Improvements ✅
(secondary)
-3.6% [-6.8%, -0.5%] 7
All ❌✅ (primary) -0.6% [-2.1%, 0.5%] 22

Binary size

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

Artifact size: 405.91 MiB -> 406.05 MiB (0.03%)

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. 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.

7 participants