Skip to content

perf(parser): reuse cached token kind in delimited-list loops#22841

Merged
graphite-app[bot] merged 1 commit into
mainfrom
perf/parser-delimited-list-cached-kind
May 29, 2026
Merged

perf(parser): reuse cached token kind in delimited-list loops#22841
graphite-app[bot] merged 1 commit into
mainfrom
perf/parser-delimited-list-cached-kind

Conversation

@Boshen

@Boshen Boshen commented May 29, 2026

Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added the A-parser Area - Parser label May 29, 2026
@codspeed-hq

codspeed-hq Bot commented May 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks


Comparing perf/parser-delimited-list-cached-kind (3cc3746) with main (1e62653)

Open in CodSpeed

@Boshen Boshen force-pushed the perf/parser-delimited-list-cached-kind branch 2 times, most recently from 6ba743f to 3cc3746 Compare May 29, 2026 17:34
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 29, 2026

Boshen commented May 29, 2026

Copy link
Copy Markdown
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)
@graphite-app graphite-app Bot force-pushed the perf/parser-delimited-list-cached-kind branch from 3cc3746 to 7e3a567 Compare May 29, 2026 17:47
@graphite-app graphite-app Bot merged commit 7e3a567 into main May 29, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 29, 2026
@graphite-app graphite-app Bot deleted the perf/parser-delimited-list-cached-kind branch May 29, 2026 17:53
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant