Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Oct 7, 2025

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

Copilot AI review requested due to automatic review settings October 7, 2025 12:17
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 7, 2025

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 hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Oct 7, 2025
Copy link
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

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 duplicate cur_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-hq
Copy link

codspeed-hq bot commented Oct 7, 2025

CodSpeed Performance Report

Merging #14411 will not alter performance

Comparing perf-cache-cur-kind (8f056ad) with main (2b6a3b4)

Summary

✅ 37 untouched

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
Copy link
Member Author

Boshen commented Oct 7, 2025

Merge activity

  • Oct 7, 12:24 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 7, 12:24 PM UTC: Boshen added this pull request to the Graphite merge queue.
  • Oct 7, 12:29 PM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'Test NAPI').
  • Oct 7, 1:42 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 7, 1:42 PM UTC: Boshen added this pull request to the Graphite merge queue.
  • Oct 7, 1:44 PM UTC: The Graphite merge queue couldn't merge this PR because it was in draft mode.
  • Oct 7, 1:48 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 7, 1:48 PM UTC: Boshen added this pull request to the Graphite merge queue.
  • Oct 7, 1:48 PM UTC: Merged by the Graphite merge queue.

graphite-app bot pushed a commit that referenced this pull request Oct 7, 2025
## 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)
@graphite-app graphite-app bot force-pushed the perf-cache-cur-kind branch from fbc54ef to ae9ebe9 Compare October 7, 2025 12:25
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
@Boshen Boshen marked this pull request as draft October 7, 2025 12:59
@github-actions github-actions bot added the A-isolated-declarations Isolated Declarations label Oct 7, 2025
@Boshen Boshen force-pushed the perf-cache-cur-kind branch 2 times, most recently from 1b70490 to 64bb9fd Compare October 7, 2025 13:27
@Boshen Boshen marked this pull request as ready for review October 7, 2025 13:42
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
## 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)
@graphite-app graphite-app bot force-pushed the perf-cache-cur-kind branch from 64bb9fd to 8f056ad Compare October 7, 2025 13:42
@Boshen Boshen marked this pull request as draft October 7, 2025 13:43
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
@Boshen Boshen marked this pull request as ready for review October 7, 2025 13:47
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
@graphite-app graphite-app bot merged commit 8f056ad into main Oct 7, 2025
27 checks passed
@graphite-app graphite-app bot deleted the perf-cache-cur-kind branch October 7, 2025 13:48
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-isolated-declarations Isolated Declarations 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.

2 participants