Skip to content

perf(estree/tokens): do not JSON-encode keyword, punctuator, etc tokens#19814

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/02-22-perf_estree_tokens_do_not_json-encode_keyword_punctuator_etc_tokens
Feb 27, 2026
Merged

perf(estree/tokens): do not JSON-encode keyword, punctuator, etc tokens#19814
graphite-app[bot] merged 1 commit intomainfrom
om/02-22-perf_estree_tokens_do_not_json-encode_keyword_punctuator_etc_tokens

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 27, 2026

After #19744, #19813, #19812, and #19796, all tokens which require special handling or can contain values which are possibly not JSON-safe are handled separately. So everything remaining (keywords, punctuators etc) are JSON-safe and can be serialized via the optimized serializer introduced for identifiers in #19744.

To reflect that EstreeIdentToken now handles a lot more than identifiers, rename it to EstreeSafeToken, and rename EstreeToken to EstreeUnsafeToken.

Large positive perf impact. +24% on ESTree tokens benchmark.

@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Feb 27, 2026
Copy link
Member Author

overlookmotel commented Feb 27, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 27, 2026

Merging this PR will improve performance by 24.01%

⚡ 1 improved benchmark
✅ 51 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation estree_tokens[checker.ts] 127.7 ms 102.9 ms +24.01%

Comparing om/02-22-perf_estree_tokens_do_not_json-encode_keyword_punctuator_etc_tokens (7369657) with om/02-22-perf_estree_tokens_do_not_json-encode_this_identifiers (efa2364)

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.

@overlookmotel overlookmotel marked this pull request as ready for review February 27, 2026 18:24
Copilot AI review requested due to automatic review settings February 27, 2026 18:24
@overlookmotel overlookmotel added A-parser Area - Parser A-linter-plugins Area - Linter JS plugins labels Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes ESTree token JSON serialization by routing JSON-safe tokens (keywords, punctuators, numbers, booleans, null, and most identifiers) through a fast manual serializer, while keeping escape-checked serialization for token values that may contain JSON-unsafe bytes.

Changes:

  • Introduces EstreeSafeToken (manual JSON assembly) and renames the previous general token type to EstreeUnsafeToken.
  • Refactors token emission to default to the safe fast-path and adds visitors to ensure string/template/JSXText tokens are emitted via the unsafe path.
  • Tightens invariants around which token kinds may reach get_token_type (debug assertion) after splitting safe vs unsafe handling.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Feb 27, 2026
Copy link
Member Author

overlookmotel commented Feb 27, 2026

Merge activity

…ns (#19814)

After #19744, #19813, #19812, and #19796, all tokens which require special handling or can contain `value`s which are possibly not JSON-safe are handled separately. So everything remaining (keywords, punctuators etc) are JSON-safe and can be serialized via the optimized serializer introduced for identifiers in #19744.

To reflect that `EstreeIdentToken` now handles a lot more than identifiers, rename it to `EstreeSafeToken`, and rename `EstreeToken` to `EstreeUnsafeToken`.

Large positive perf impact. +24% on ESTree tokens benchmark.
graphite-app bot pushed a commit that referenced this pull request Feb 27, 2026
Remove the `regex` field from `EstreeToken` and serialize regex tokens via their own dedicated type `EstreeRegExpToken`. This removes a branch and logic from `emit_token` which is the path the processes all tokens except identifiers.

This PR is actually showing as a small perf degradation (-1% on ESTree tokens benchmark). But it enables a much bigger optimization later on in #19814.
graphite-app bot pushed a commit that referenced this pull request Feb 27, 2026
Same as #19744, but for `this` identifiers in TS types. Serialize them using the same optimized `EstreeIdentToken` serializer added in that PR.

This isn't a hot path so makes little difference, but it completes the preconditions for the next PR #19814.
@graphite-app graphite-app bot force-pushed the om/02-22-perf_estree_tokens_do_not_json-encode_this_identifiers branch from efa2364 to 6260ddd Compare February 27, 2026 18:40
@graphite-app graphite-app bot force-pushed the om/02-22-perf_estree_tokens_do_not_json-encode_keyword_punctuator_etc_tokens branch from 7369657 to 81bab90 Compare February 27, 2026 18:40
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 27, 2026
Base automatically changed from om/02-22-perf_estree_tokens_do_not_json-encode_this_identifiers to main February 27, 2026 18:48
@graphite-app graphite-app bot merged commit 81bab90 into main Feb 27, 2026
22 checks passed
@graphite-app graphite-app bot deleted the om/02-22-perf_estree_tokens_do_not_json-encode_keyword_punctuator_etc_tokens branch February 27, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter-plugins Area - Linter JS plugins 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