Skip to content

perf(ecma_parser): start oxc-style token payload rewrite#11812

Draft
kdy1 wants to merge 8 commits intomainfrom
kdy1/oxc-parser-rewrite
Draft

perf(ecma_parser): start oxc-style token payload rewrite#11812
kdy1 wants to merge 8 commits intomainfrom
kdy1/oxc-parser-rewrite

Conversation

@kdy1
Copy link
Copy Markdown
Member

@kdy1 kdy1 commented Apr 20, 2026

Description:

This starts the long-lived swc_ecma_parser performance rewrite with a parser-facing token payload refactor that follows the oxc-style plan without changing the public parser API.

What changed:

  • Buffer now owns separate current/lookahead token payload slots instead of saving and restoring lexer token_value during generic peek().
  • TypeScript parser checkpoints now persist the current payload slot directly, so backtracking restores parser state without re-shuffling lexer payload state.
  • Flow/TypeScript contextual-word checks that only need equality now use borrowed string comparisons instead of materializing or cloning Atoms on hot paths.

Why this helps:

  • It removes the generic Buffer::peek() payload swap from the main parser hot path.
  • It keeps lookahead payloads in parser-owned slots, which is closer to the target architecture for the ongoing lexer/parser rewrite.
  • It reduces unnecessary Atom work in TS/Flow ambiguity checks.

Local benchmark spot checks on April 20, 2026:

  • es/parser/colors: from roughly 4.16–4.59 µs to 3.05–3.07 µs
  • es/lexer/colors: from roughly 1.15–1.19 µs to 0.90–0.93 µs
  • es/parser/typescript: measured at roughly 51.3–52.5 ms after the change

Validation used:

  • git submodule update --init --recursive
  • cargo fmt --all
  • cargo test -p swc_ecma_parser
  • cargo bench -p swc_ecma_parser --bench parser -- --warm-up-time 0.01 --measurement-time 0.01 'es/parser/colors'
  • cargo bench -p swc_ecma_parser --bench lexer -- --warm-up-time 0.01 --measurement-time 0.01 'es/lexer/colors'
  • cargo bench -p swc_ecma_parser --bench parser -- --warm-up-time 0.01 --measurement-time 0.01 'es/parser/typescript'

This is phase 1 of the rewrite PR. After the Benchmark workflow finishes, I plan to use the CodSpeed report to choose the next optimization step.

BREAKING CHANGE:

None.

Related issue (if exists):

N/A

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 20, 2026

⚠️ No Changeset found

Latest commit: 5439aaf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 20, 2026

Merging this PR will not alter performance

✅ 219 untouched benchmarks
⏩ 31 skipped benchmarks1


Comparing kdy1/oxc-parser-rewrite (5439aaf) with main (fe38342)

Open in CodSpeed

Footnotes

  1. 31 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 27M (27766728 bytes)

Commit: 634d294

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant