Skip to content

perf(napi/parser): do not generate tokens except in tests#21811

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-27-perf_napi_parser_do_not_generate_tokens_except_in_tests
Apr 27, 2026
Merged

perf(napi/parser): do not generate tokens except in tests#21811
graphite-app[bot] merged 1 commit intomainfrom
om/04-27-perf_napi_parser_do_not_generate_tokens_except_in_tests

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 27, 2026

#19885 added support for tokens in oxc-parser, but only via raw transfer and behind an undocumented experimentalTokens option. It's currently only used in tests for the purpose of conformance testing.

This slowed down oxc-parser a little (very little as the difference in execution time on Rust side is dwarfed by the cost of JSON transfer).

The worse effect is that it caused a large binary size increase in Rolldown (rolldown/rolldown#9166) because Rolldown re-exports napi/parser's Rust code, which meant that Rolldown now contains 2 versions of Oxc's parser with different ParserConfigs, leading to the entire parser being compiled and included in the binary twice.

Fix this by introducing a Cargo feature tokens on napi/parser crate. Only when tokens feature is enabled is a ParserConfig which generates tokens used. When disabled (the default), the default ParserConfig which does not produce tokens is used.

Enable the tokens feature only in tests.

Copy link
Copy Markdown
Member Author


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 changes, fast-track this PR to the front of the merge queue

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.

@overlookmotel overlookmotel self-assigned this Apr 27, 2026
@overlookmotel overlookmotel added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Apr 27, 2026
@overlookmotel overlookmotel marked this pull request as ready for review April 27, 2026 02:06
Copilot AI review requested due to automatic review settings April 27, 2026 02:06
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Apr 27, 2026
Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 27, 2026

Merge activity

Copy link
Copy Markdown
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

This PR makes token generation in napi/parser opt-in via a Cargo feature to avoid unnecessary runtime work and (more importantly) prevent downstream binary-size bloat caused by compiling the parser twice with different configs.

Changes:

  • Introduces an optional Cargo feature (tokens) that pulls in oxc_estree_tokens only when enabled.
  • Gates token-related parsing/configuration and raw-transfer token conversion behind #[cfg(feature = "tokens")].
  • Enables the tokens feature only for the build-test script so conformance tests can still validate tokens.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
napi/parser/src/raw_transfer.rs Guards token conversion/imports behind the tokens feature; defaults to (0,0) offsets when disabled.
napi/parser/src/lib.rs Uses the default no-tokens parser config unless the tokens feature is enabled.
napi/parser/package.json Builds tests with --features tokens so token snapshots/conformance tests continue to work.
napi/parser/Cargo.toml Makes oxc_estree_tokens optional and adds a tokens feature that enables it.

#19885 added support for tokens in `oxc-parser`, but only via raw transfer and behind an undocumented `experimentalTokens` option. It's currently only used in tests for the purpose of conformance testing.

This slowed down `oxc-parser` a little (very little as the difference in execution time on Rust side is dwarfed by the cost of JSON transfer).

The worse effect is that it caused a large binary size increase in Rolldown (rolldown/rolldown#9166) because Rolldown re-exports `napi/parser`'s Rust code, which meant that Rolldown now contains 2 versions of Oxc's parser with different `ParserConfig`s, leading to the entire parser being compiled and included in the binary twice.

Fix this by introducing a Cargo feature `tokens` on `napi/parser` crate. Only when `tokens` feature is enabled is a `ParserConfig` which generates tokens used. When disabled (the default), the default `ParserConfig` which does not produce tokens is used.

Enable the `tokens` feature only in tests.
@graphite-app graphite-app Bot force-pushed the om/04-27-perf_napi_parser_do_not_generate_tokens_except_in_tests branch from 727655b to 9fa362e Compare April 27, 2026 02:10
@graphite-app graphite-app Bot merged commit 9fa362e into main Apr 27, 2026
25 checks passed
@graphite-app graphite-app Bot deleted the om/04-27-perf_napi_parser_do_not_generate_tokens_except_in_tests branch April 27, 2026 02:14
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 27, 2026
camc314 pushed a commit that referenced this pull request Apr 27, 2026
### 💥 BREAKING CHANGES

- 502e804 ast: [**BREAKING**] Reduce size of `TSTypePredicateName`
(#21711) (overlookmotel)
- 5651539 ast: [**BREAKING**] Reduce size of `JSXExpression` (#21710)
(overlookmotel)
- c44e280 ast: [**BREAKING**] Reduce size of `ArrayExpressionElement`
(#21709) (overlookmotel)
- c5b3deb syntax: [**BREAKING**] Remove `CommentNodeId` (#21679)
(overlookmotel)

### 🚀 Features

- b738a39 allocator: Add `Allocator::cursor_ptr` method (#21773)
(overlookmotel)
- 678767e ast: Generate node_id accessors for AST enum wrappers (#21653)
(camc314)
- f091d77 minifier: Inline constant spread elements into arrays (#21095)
(Armano)

### 🐛 Bug Fixes

- 0d608c2 minifier: Preserve raw CR in template literals (#21645)
(Dunqing)
- a889ea9 minifier: Track pure functions in DCE mode (#21722) (Dunqing)
- 674dfac allocator: `Arena` retry allocation when chunk size approaches
maximum (#21777) (overlookmotel)
- f130cc0 allocator: Fix arithmetic overflow in
`Arena::new_chunk_memory_details` (#21745) (overlookmotel)
- b9bf239 allocator: Fix UB in `Arena::grow_zeroed` (#21739)
(overlookmotel)
- d2b9389 allocator: Clippy warning when building without `testing`
feature (#21681) (camc314)
- 503dc86 codegen: Map sourcemaps from visible output starts (#21662)
(Dunqing)
- c92bd3b transformer: Use SPAN for synthesized helper calls to prevent
comment misattribution (#21578) (Dunqing)
- 0d80441 codegen: Add mapping before printing `#` for private ident
(#21619) (camc314)

### ⚡ Performance

- 9fa362e napi/parser: Do not generate tokens except in tests (#21811)
(overlookmotel)
- 0044392 allocator: Reduce branches when allocating new chunk (#21776)
(overlookmotel)
- 7896bd0 allocator: `Allocator::used_bytes` do not use chunk iterator
(#21771) (overlookmotel)
- a5c562f allocator: Remove check in `Arena::new_chunk_memory_details`
(#21750) (overlookmotel)
- 35bbe1f allocator: `Arena` use unchecked size round up where
guaranteed no overflow (#21743) (overlookmotel)
- ffe229b allocator: Remove unnecessary check from
`Arena::try_alloc_layout_slow_impl` (#21732) (overlookmotel)
- 72fece5 allocator: Use `NonNull::offset_from_unsigned` in
`Arena::chunk_capacity` (#21731) (overlookmotel)
- cab32ae ast: Add `#[inline(always)]` to `node_id` methods on enums
with all variants unboxed (#21707) (overlookmotel)
- b179688 parser: Allocate `TriviaBuilder` comments in the arena
(#21512) (Boshen)
- 2290f31 lexer: Fix perf of `Token::set_*` methods on Rust 1.95.0
(#21659) (overlookmotel)
- 1b58029 allocator: Move code into cold path in `Arena::alloc_layout`
(#21622) (overlookmotel)
- 3cf7cef allocator: Reduce instructions on allocation hot path (#21510)
(overlookmotel)

### 📚 Documentation

- ce65070 data_structures: Document why `as_ref` and `as_mut` on
`NonNullConst` and `NonNullMut` take `self` (#21800) (overlookmotel)
- 93b7dbd allocator: Improve doc comments for `ChunkFooter` (#21733)
(overlookmotel)
- 295db8d transformer: Fix comment (#21717) (overlookmotel)
- 5c93af8 ast: Add comments explaining `#[inline(always)]` to `node_id`
methods on enums (#21706) (overlookmotel)
- e4cea25 transform: Use the `node:` namespace in the example (#19998)
(루밀LuMir)

### 🛡️ Security

- d8076c9 deps: Update rolldown (#21639) (renovate)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
@overlookmotel
Copy link
Copy Markdown
Member Author

Seems like this didn't have the desired effect in Rolldown: rolldown/rolldown#9166 (comment)

@camc314
Copy link
Copy Markdown
Contributor

camc314 commented May 2, 2026

Seems like this didn't have the desired effect in Rolldown: rolldown/rolldown#9166 (comment)

I think this had a positive effect. but there are still other issues ther.

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.

3 participants