Skip to content

Conversation

@lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Nov 27, 2025

  • Removes branching in some cases where it was used to calculate slices.
  • Avoids indexing into arrays past their length.
  • Renames nodeTokens to tokenList. In the first few methods implemented, they contained tokens of the given node. Not the case for later methods, but the misnomer stayed.
  • Improves consistency in comments. Clarifies that binary searches yield tokens before or after a certain point, they are not necessarily within the range we care about.

Copilot AI review requested due to automatic review settings November 27, 2025 02:11
@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-performance Category - Solution not expected to change functional behavior, only performance labels Nov 27, 2025
Copilot finished reviewing on behalf of lilnasy November 27, 2025 02:13
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

This PR optimizes token retrieval methods in the linter plugin by improving performance through several targeted changes: removing unnecessary branching, preventing out-of-bounds array access, renaming variables for clarity, and improving comment consistency.

Key changes:

  • Optimizes getTokens() to avoid unnecessary array operations when filtering with count limits and adds bounds checking to prevent indexing past array length
  • Refactors binary search in getLastToken() with a cleaner algorithm and adds explicit bounds checking
  • Renames nodeTokens variable to tokenList throughout the file for better semantic accuracy

Reviewed changes

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

File Description
apps/oxlint/test/tokens.test.ts Fixes incorrect range values in tests (corrects [0, 11] to [0, 10] to match actual string length)
apps/oxlint/src-js/plugins/tokens.ts Refactors token retrieval methods with performance optimizations: adds bounds checking, removes branching in favor of nullish coalescing, optimizes filtering loops, and renames nodeTokens to tokenList for clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lilnasy lilnasy force-pushed the token-perf branch 2 times, most recently from 4debb5e to c071391 Compare November 27, 2025 02:17
@overlookmotel overlookmotel merged commit d3a34f8 into oxc-project:main Nov 27, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins 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