Skip to content

perf(parser): reduce try_parse usage in favour of lookahead#21532

Merged
graphite-app[bot] merged 1 commit intomainfrom
perf/parser-reduce-try-parse
Apr 19, 2026
Merged

perf(parser): reduce try_parse usage in favour of lookahead#21532
graphite-app[bot] merged 1 commit intomainfrom
perf/parser-reduce-try-parse

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented Apr 17, 2026

Summary

try_parse rewinds on failure, but it keeps AST nodes the failed branch
allocated into the arena until end of parse, uses the more expensive
checkpoint_with_error_recovery (which full-clones the errors vec), and
forces the lexer to re-scan the same bytes on the committed reparse.
Where the discriminator is just a token peek, lookahead (or a direct
peek_token) is strictly cheaper.

Conformance unchanged: no snapshot drift on Test262, Babel, or TypeScript
suites.

part of #21540

🤖 Generated with Claude Code

@github-actions github-actions Bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Apr 17, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c03be268fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/oxc_parser/src/modifiers.rs Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 17, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing perf/parser-reduce-try-parse (4e23c2f) with main (611b3b6)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (b0817ae) during the generation of this report, so 611b3b6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown
Member

@camchenry camchenry left a comment

Choose a reason for hiding this comment

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

makes sense to me I think, the number of allocations reduced looks great

Comment thread crates/oxc_parser/src/js/class.rs
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Apr 19, 2026
Copy link
Copy Markdown
Member Author

Boshen commented Apr 19, 2026

Merge activity

## Summary

`try_parse` rewinds on failure, but it keeps AST nodes the failed branch
allocated into the arena until end of parse, uses the more expensive
`checkpoint_with_error_recovery` (which full-clones the errors vec), and
forces the lexer to re-scan the same bytes on the committed reparse.
Where the discriminator is just a token peek, `lookahead` (or a direct
`peek_token`) is strictly cheaper.

Conformance unchanged: no snapshot drift on Test262, Babel, or TypeScript
suites.

part of #21540

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app Bot force-pushed the perf/parser-reduce-try-parse branch from 4e23c2f to e45efc5 Compare April 19, 2026 03:10
@graphite-app graphite-app Bot merged commit e45efc5 into main Apr 19, 2026
27 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 19, 2026
@graphite-app graphite-app Bot deleted the perf/parser-reduce-try-parse branch April 19, 2026 03:17
camc314 added a commit that referenced this pull request Apr 20, 2026
### 🐛 Bug Fixes

- 48967e8 isolated_declarations: Drop required type check for private
parameter properties on private constructors (#21515) (Dunqing)
- 91e5bde transformer/typescript: Preserve computed-key static block
when class has an empty constructor (#21562) (Dunqing)
- 50e9d26 mangler: Assign correct slot to shadowed function-expression
names (#21535) (Dunqing)
- 065ce47 isolated_declarations: Collect types from private accessors
for paired inference (#21516) (Dunqing)
- 00fc136 codegen: Preserve coverage comments before object properties
(#21312) (bab)
- d676e0c minifier: Mark LHS of `??=` as read when converting from `==
null &&` (#21546) (Gunnlaugur Thor Briem)

### ⚡ Performance

- e45efc5 parser: Reduce `try_parse` usage in favour of `lookahead`
(#21532) (Boshen)
- ddb1bf8 parser: Avoid redundant `IdentifierReference` clone in
shorthand property (#21511) (Boshen)
- be2b392 allocator: Store pointers directly in `Arena` (#21483)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Cameron <cameron.clark@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants