Skip to content

perf(linter/plugins): faster conversion of span to Location#20507

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_
Mar 21, 2026
Merged

perf(linter/plugins): faster conversion of span to Location#20507
graphite-app[bot] merged 1 commit intomainfrom
om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 18, 2026

Speed up computeLoc, which converts a start + end offset pair to a Location of form { start: { line: ?, column: ? }, end: { line: ?, column: ? } }.

computeLoc is only called with start and end pairs from AST nodes, tokens, and comments, which are all produced by Oxc's parser, so it's guaranteed that start < end.

Use this invariant for 2 optimizations:

  1. Fast path for common case where start and end are on same line.
  2. Reduce range of lines which are searched looking for end to only lines which are after the line start is on. end can't be on an earlier line, so there's not point search them.

Copy link
Member Author

overlookmotel commented Mar 18, 2026


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 changes, fast-track this PR to the front of 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review March 18, 2026 23:09
@overlookmotel overlookmotel requested a review from camc314 as a code owner March 18, 2026 23:09
Copilot AI review requested due to automatic review settings March 18, 2026 23:09
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 computeLoc in apps/oxlint/src-js/plugins/location.ts, which converts source spans (start/end offsets) into { start: { line, column }, end: { line, column } } locations used by nodes/tokens/comments during linting.

Changes:

  • Adds a fast path in computeLoc for the common case where start and end are on the same line.
  • Narrows the binary search range for locating end to lines at/after the line containing start.
  • Refactors getLineColumnFromOffset to return its { line, column } result directly (removing the helper that populated an output object).

@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch from 860d9dc to a229810 Compare March 19, 2026 00:11
@overlookmotel overlookmotel self-assigned this Mar 19, 2026
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 20, 2026
@overlookmotel overlookmotel removed the 0-merge Merge with Graphite Merge Queue label Mar 20, 2026
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Mar 20, 2026 — with Graphite App
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch from a229810 to ee2f73e Compare March 21, 2026 12:21
@overlookmotel overlookmotel force-pushed the om/03-18-docs_linter_plugins_correct_comment_about_offset_to_line-column_conversion branch from f3c82c6 to f5c738d Compare March 21, 2026 12:21
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch from ee2f73e to bf0cd7d Compare March 21, 2026 12:33
@overlookmotel overlookmotel force-pushed the om/03-18-docs_linter_plugins_correct_comment_about_offset_to_line-column_conversion branch from f5c738d to 897dc88 Compare March 21, 2026 12:33
@graphite-app graphite-app bot force-pushed the om/03-18-docs_linter_plugins_correct_comment_about_offset_to_line-column_conversion branch from 897dc88 to bfa3661 Compare March 21, 2026 12:54
@graphite-app graphite-app bot force-pushed the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch from bf0cd7d to deb418b Compare March 21, 2026 12:54
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 21, 2026

Merge activity

Speed up `computeLoc`, which converts a `start` + `end` offset pair to a `Location` of form `{ start: { line: ?, column: ? }, end: { line: ?, column: ? } }`.

`computeLoc` is only called with `start` and `end` pairs from AST nodes, tokens, and comments, which are all produced by Oxc's parser, so it's guaranteed that `start < end`.

Use this invariant for 2 optimizations:

1. Fast path for common case where `start` and `end` are on same line.
2. Reduce range of lines which are searched looking for end to only lines which are after the line `start` is on. `end` can't be on an earlier line, so there's not point search them.
@graphite-app graphite-app bot force-pushed the om/03-18-docs_linter_plugins_correct_comment_about_offset_to_line-column_conversion branch from bfa3661 to f064f80 Compare March 21, 2026 13:02
@graphite-app graphite-app bot force-pushed the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch from deb418b to 336f7f7 Compare March 21, 2026 13:03
Base automatically changed from om/03-18-docs_linter_plugins_correct_comment_about_offset_to_line-column_conversion to main March 21, 2026 13:05
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 21, 2026
@graphite-app graphite-app bot merged commit 336f7f7 into main Mar 21, 2026
24 checks passed
@graphite-app graphite-app bot deleted the om/03-18-perf_linter_plugins_faster_conversion_of_span_to_location_ branch March 21, 2026 13:08
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