perf(estree/tokens): do not JSON-encode keyword, punctuator, etc tokens#19814
Merged
graphite-app[bot] merged 1 commit intomainfrom Feb 27, 2026
Conversation
This was referenced Feb 27, 2026
Member
Author
Merging this PR will improve performance by 24.01%
Performance Changes
Comparing Footnotes
|
Contributor
There was a problem hiding this comment.
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 toEstreeUnsafeToken. - 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.
Member
Author
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.
efa2364 to
6260ddd
Compare
7369657 to
81bab90
Compare
Base automatically changed from
om/02-22-perf_estree_tokens_do_not_json-encode_this_identifiers
to
main
February 27, 2026 18:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
EstreeIdentTokennow handles a lot more than identifiers, rename it toEstreeSafeToken, and renameEstreeTokentoEstreeUnsafeToken.Large positive perf impact. +24% on ESTree tokens benchmark.