perf(parser): reuse cached token kind in delimited-list loops#22841
Merged
Conversation
Merging this PR will not alter performance
Comparing |
6ba743f to
3cc3746
Compare
Member
Author
Merge activity
|
## What In `parse_delimited_list` and `parse_delimited_list_into` (`cursor.rs`), the loop already caches `let kind = self.cur_kind();` at the top of each iteration, then re-reads the same token via `if !self.at(separator)` — which expands to `self.token.kind() == separator`. No token mutation (`advance`/`bump`/`next_token`) happens between the cache and the separator check, so `!self.at(separator)` is provably identical to `kind != separator`. This reuses the already-loaded `kind` and avoids re-reading `self.token` once per element of every array literal, object literal, parameter list, and argument list. ## Correctness Semantics-preserving — no change to parse results or diagnostics. - `cargo test -p oxc_parser`: pass - `cargo coverage -- parser`: zero conformance snapshot diff (Test262 / TypeScript / Babel / estree) - `just fmt` + `cargo clippy -p oxc_parser --all-features --all-targets`: clean ## Performance A micro-optimization (removes one in-register/L1 token-field comparison per delimited-list element). Measured via an interleaved A/B against a parse-invariant control (`estree/checker.ts`); combined with the modifier-path change it lands ~0.5–1% on declaration/member-dense files (`binder.ts`), noise-level elsewhere. The main value is making the reuse of the cached `kind` explicit. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
3cc3746 to
7e3a567
Compare
camc314
pushed a commit
that referenced
this pull request
Jun 1, 2026
### 🚀 Features - 9c71f2e ast, codegen, formatter: Add `WithClauseKeyword::as_str` helper and use it (#22791) (camc314) ### 🐛 Bug Fixes - cf5769c parser: Reject TypeScript declarations in single-statement context (#22827) (Boshen) - c360fb6 parser: Reject generators in ambient contexts and overload signatures (TS1221/TS1222) (#22848) (Boshen) - cc60d8d parser: Reject invalid index signature parameter types (TS1268/TS1337) (#22852) (Boshen) - 3d13e29 parser: Reject `declare` in an already-ambient context (TS1038) (#22850) (Boshen) - 5152854 parser: Reject statements in ambient contexts (TS1036) (#22849) (Boshen) - 4f9afc5 parser: Reject `export as namespace` inside a namespace body (TS1316) (#22846) (Boshen) - 2eafea6 parser: Reject function implementations in ambient contexts (TS1183) (#22845) (Boshen) - c645615 parser: Reject incompatible class member modifiers (#22843) (Boshen) - 276b78b parser: Reject module-referencing imports/exports in a namespace body (#22836) (Boshen) - 842ed1c parser: Parse `class implements` with `implements` as the class name (#22801) (Boshen) ### ⚡ Performance - 7e3a567 parser: Reuse cached token kind in delimited-list loops (#22841) (Boshen) - 9e741c2 parser: Use peek_token instead of lookahead on the modifier path (#22842) (Boshen) - 9e496a7 semantic: Defer declare lookup for empty accessors (#22810) (camc314)
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.
What
In
parse_delimited_listandparse_delimited_list_into(cursor.rs), the loop already cacheslet kind = self.cur_kind();at the top of each iteration, then re-reads the same token viaif !self.at(separator)— which expands toself.token.kind() == separator.No token mutation (
advance/bump/next_token) happens between the cache and the separator check, so!self.at(separator)is provably identical tokind != separator. This reuses the already-loadedkindand avoids re-readingself.tokenonce per element of every array literal, object literal, parameter list, and argument list.Correctness
Semantics-preserving — no change to parse results or diagnostics.
cargo test -p oxc_parser: passcargo coverage -- parser: zero conformance snapshot diff (Test262 / TypeScript / Babel / estree)just fmt+cargo clippy -p oxc_parser --all-features --all-targets: cleanPerformance
A micro-optimization (removes one in-register/L1 token-field comparison per delimited-list element). Measured via an interleaved A/B against a parse-invariant control (
estree/checker.ts); combined with the modifier-path change it lands ~0.5–1% on declaration/member-dense files (binder.ts), noise-level elsewhere. The main value is making the reuse of the cachedkindexplicit.🤖 Generated with Claude Code