-
-
Notifications
You must be signed in to change notification settings - Fork 721
perf(parser): cache cur_kind() to eliminate redundant calls #14411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Performance optimization to reduce redundant token kind extraction in parser hot paths by caching cur_kind() results before compound conditional checks.
- Cache
cur_kind()in local variables to eliminate redundant calls in compound boolean expressions - Inline
has_fatal_error()logic to avoid duplicatecur_kind()calls - Convert
self.at(Kind::X)patterns to direct kind comparisons where appropriate
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/ts/types.rs | Cache kind for 3 compound checks to reduce redundant token extraction |
| crates/oxc_parser/src/js/module.rs | Cache kind for import statement parsing optimization |
| crates/oxc_parser/src/js/arrow.rs | Cache kind for arrow function parameter detection |
| crates/oxc_parser/src/cursor.rs | Inline fatal error checks and cache kind in hot parsing loop |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Performance ReportMerging #14411 will not alter performanceComparing Summary
|
Merge activity
|
## Summary Optimization to reduce redundant token kind extraction in hot paths by caching `cur_kind()` results before compound checks. ## Problem - Compound checks like `self.at(X) || self.at(Y)` call `cur_kind()` twice - Pattern `self.at(close) || self.has_fatal_error()` calls `cur_kind()` twice since `has_fatal_error()` internally calls it - Token kind extraction involves bit-packing operations: `((self.0 >> 64) & 0xFF) as u8` ## Solution Cache `cur_kind()` in a local variable before compound checks to eliminate redundant calls. ## Changes - **`cursor.rs:parse_delimited_list()`**: Hot loop parsing arrays, objects, parameters - reduced from 2-3 calls per iteration to 1 - **`arrow.rs:68`**: Cached kind for `LParen`/`LAngle` check - **`module.rs:101`**: Cached kind for `LCurly`/`Star` check - **`types.rs`**: Fixed 3 locations (lines 91, 558, 1188) with double `at()` calls ## Impact Every JavaScript array, object literal, function parameter list, and TypeScript type now extracts the token kind fewer times during parsing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fbc54ef to
ae9ebe9
Compare
1b70490 to
64bb9fd
Compare
## Summary Optimization to reduce redundant token kind extraction in hot paths by caching `cur_kind()` results before compound checks. ## Problem - Compound checks like `self.at(X) || self.at(Y)` call `cur_kind()` twice - Pattern `self.at(close) || self.has_fatal_error()` calls `cur_kind()` twice since `has_fatal_error()` internally calls it - Token kind extraction involves bit-packing operations: `((self.0 >> 64) & 0xFF) as u8` ## Solution Cache `cur_kind()` in a local variable before compound checks to eliminate redundant calls. ## Changes - **`cursor.rs:parse_delimited_list()`**: Hot loop parsing arrays, objects, parameters - reduced from 2-3 calls per iteration to 1 - **`arrow.rs:68`**: Cached kind for `LParen`/`LAngle` check - **`module.rs:101`**: Cached kind for `LCurly`/`Star` check - **`types.rs`**: Fixed 3 locations (lines 91, 558, 1188) with double `at()` calls ## Impact Every JavaScript array, object literal, function parameter list, and TypeScript type now extracts the token kind fewer times during parsing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
64bb9fd to
8f056ad
Compare
Summary
Optimization to reduce redundant token kind extraction in hot paths by caching
cur_kind()results before compound checks.Problem
self.at(X) || self.at(Y)callcur_kind()twiceself.at(close) || self.has_fatal_error()callscur_kind()twice sincehas_fatal_error()internally calls it((self.0 >> 64) & 0xFF) as u8Solution
Cache
cur_kind()in a local variable before compound checks to eliminate redundant calls.Changes
cursor.rs:parse_delimited_list(): Hot loop parsing arrays, objects, parameters - reduced from 2-3 calls per iteration to 1arrow.rs:68: Cached kind forLParen/LAnglecheckmodule.rs:101: Cached kind forLCurly/Starchecktypes.rs: Fixed 3 locations (lines 91, 558, 1188) with doubleat()callsImpact
Every JavaScript array, object literal, function parameter list, and TypeScript type now extracts the token kind fewer times during parsing.
🤖 Generated with Claude Code