perf(ast): mark AstKind::span as #[inline]#20585
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR adds an #[inline] hint to AstKind’s GetSpan::span implementation to help prevent future performance regressions now that AST node span fields are guaranteed to be laid out consistently.
Changes:
- Add documentation explaining why
AstKind::spanshould be cheap (consistentspanfield placement). - Add
#[inline]to theGetSpan for AstKind<'_>span()implementation in the generator and regenerated output.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/ast_kind.rs | Updates the code generator to emit docs + #[inline] on AstKind’s GetSpan::span. |
| crates/oxc_ast/src/generated/ast_kind.rs | Regenerates AstKind to include the new docs + #[inline] on span(). |
9eaf443 to
c9edd39
Compare
b258884 to
2064ade
Compare
Merge activity
|
Now that `AstKind`'s variants are all structs (no enums any more), and #20584 has ensured that `Span` is in a consistent position in all structs, `AstKind::span` should boil down to a single operation - a pointer read. Therefore, mark it `#[inline]`. Note: `Span` was already in a consistent position prior to #20584, but that was more by accident than anything else. Now it's guaranteed. But this change won't make a difference to perf, it just guards against a perf regression in future.
2064ade to
c6ea0a0
Compare
c9edd39 to
3420abb
Compare
Similar to #20585. As `AstKind`'s variants are all structs (no enums any more), and all structs have an `AstKind`, `AstKind::address` method boils down to a no-op. So mark it `#[inline]`. Also remove some defunct code from `AstKind` codegen which was handling when an `AstKind` refers to an enum. This circumstance is no longer possible, so remove this code.
Now that `AstKind`'s variants are all structs (no enums any more), and oxc-project#20584 has ensured that `Span` is in a consistent position in all structs, `AstKind::span` should boil down to a single operation - a pointer read. Therefore, mark it `#[inline]`. Note: `Span` was already in a consistent position prior to oxc-project#20584, but that was more by accident than anything else. Now it's guaranteed. But this change won't make a difference to perf, it just guards against a perf regression in future.
Similar to oxc-project#20585. As `AstKind`'s variants are all structs (no enums any more), and all structs have an `AstKind`, `AstKind::address` method boils down to a no-op. So mark it `#[inline]`. Also remove some defunct code from `AstKind` codegen which was handling when an `AstKind` refers to an enum. This circumstance is no longer possible, so remove this code.

Now that
AstKind's variants are all structs (no enums any more), and #20584 has ensured thatSpanis in a consistent position in all structs,AstKind::spanshould boil down to a single operation - a pointer read. Therefore, mark it#[inline].Note:
Spanwas already in a consistent position prior to #20584, but that was more by accident than anything else. Now it's guaranteed. But this change won't make a difference to perf, it just guards against a perf regression in future.