refactor(estree/tokens): convert token kinds to ESTreeKind#19875
Conversation
Merging this PR will degrade performance by 9.57%
Performance Changes
Comparing Footnotes
|
a0c0e12 to
95e7606
Compare
95e7606 to
fe2d845
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the raw transfer token processing in oxc_estree_tokens to pre-convert all token kinds to a compact ESTreeKind enum (12 variants) before sending to the JS side, instead of leaving the full Kind enum (169 variants) for JS to handle.
Changes:
- Introduces a new
ESTreeKindenum with 12 variants mirroring ESTree token types, plus aCONVERSION_TABLEmapping all 169Kindvariants to theirESTreeKindequivalents. - Updates
RawContext::advance_toandfinishto eagerly convert skipped tokens' kinds toESTreeKinddiscriminants stored asKindbyte values, and updates all explicit emit methods to useESTreeKindinstead ofKind. - Removes
Kind::JSXIdentifierfrom the lexer'sKindenum (it was only used for ESTree conversion, never produced by the lexer), reducingKind::VARIANTS.len()from 170 to 169.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/oxc_parser/src/lexer/kind.rs |
Removes Kind::JSXIdentifier (no longer needed as a token kind) |
crates/oxc_estree_tokens/src/lib.rs |
Registers the new estree_kind module |
crates/oxc_estree_tokens/src/estree_kind.rs |
New file defining ESTreeKind enum and CONVERSION_TABLE |
crates/oxc_estree_tokens/src/raw_transfer.rs |
Updates token kind handling to use ESTreeKind throughout |
fe2d845 to
cd255b5
Compare
ad5f1b4 to
4efb610
Compare
cd255b5 to
f53737d
Compare
4efb610 to
3edfe90
Compare
Merge activity
|
#19856 added an `update_tokens` function to update tokens, ready to be sent over to JS side via raw transfer. Except for tokens where the token `Kind` needs specific modification, this function left token's `Kind`s alone. Unfortunately this means we have to handle all 169 variants of `Kind` on JS side. Instead, convert them to `ESTreeKind`, which has only the 11 variants which ESTree tokens have. This change has negative perf impact on Rust side (-9%), but it improves perf on JS side in return.
3edfe90 to
ee4982b
Compare
f53737d to
449080c
Compare

#19856 added an
update_tokensfunction to update tokens, ready to be sent over to JS side via raw transfer.Except for tokens where the token
Kindneeds specific modification, this function left token'sKinds alone. Unfortunately this means we have to handle all 169 variants ofKindon JS side.Instead, convert them to
ESTreeKind, which has only the 11 variants which ESTree tokens have.This change has negative perf impact on Rust side (-9%), but it improves perf on JS side in return.