Skip to content

perf(linter/plugins): recycle Location objects#20491

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

perf(linter/plugins): recycle Location objects#20491
graphite-app[bot] merged 1 commit intomainfrom
om/03-18-perf_linter_plugins_recycle_location_objects

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 18, 2026

Add an object pool for Location objects, and recycle them across files.

Usually, only a minority of AST nodes, tokens, and comments will have their loc property accessed, so the pool is not pre-populated - Location objects are only created on demand.

Like the other object pools, once warmed up over the first batch of files, the fast path for "use an existing object from the pool" will be consistently taken and no further objects will be allocated. All Location objects will soon graduate to "old space" where they don't impede or trigger minor GC.

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.

@github-actions github-actions bot added the A-linter-plugins Area - Linter JS plugins label Mar 18, 2026
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Mar 18, 2026
@overlookmotel overlookmotel self-assigned this Mar 18, 2026
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_recycle_location_objects branch from 8f03505 to 733bd17 Compare March 18, 2026 16:28
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_reduce_operations_in_binary_search branch 2 times, most recently from 5c85a67 to cea62d4 Compare March 18, 2026 19:55
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_recycle_location_objects branch 2 times, most recently from 133b026 to 495ab73 Compare March 18, 2026 19:58
@overlookmotel overlookmotel marked this pull request as ready for review March 18, 2026 20:03
@overlookmotel overlookmotel requested a review from camc314 as a code owner March 18, 2026 20:03
Copilot AI review requested due to automatic review settings March 18, 2026 20:03
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 reduces GC pressure during linting by introducing an object pool for Location (and its nested LineColumn) instances, recycling them across files instead of allocating new objects as loc is accessed.

Changes:

  • Added a Location object pool in location.ts and updated computeLoc() to reuse pooled objects.
  • Renamed the per-file cleanup hook from resetLines() to resetLinesAndLocs() and reset the Location pool alongside line caches.
  • Updated SourceCode reset flow to call the new combined reset function.

Reviewed changes

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

File Description
apps/oxlint/src-js/plugins/source_code.ts Switches reset logic to resetLinesAndLocs() so Location pooling is reset per file.
apps/oxlint/src-js/plugins/location.ts Implements Location pooling and refactors line/column computation to populate existing objects.

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 introduces pooling for Location objects used by the linter’s JS-side SourceCode/AST/token/comment location APIs, to reduce per-file allocations and GC overhead during linting runs.

Changes:

  • Add a Location object pool in location.ts (reusing Location + nested LineColumn objects across files).
  • Replace resetLines() with resetLinesAndLocs() and wire it into the per-file reset path.
  • Refactor line/column computation to populate pre-existing LineColumn objects (supporting pooled Location instances).

Reviewed changes

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

File Description
apps/oxlint/src-js/plugins/source_code.ts Switch per-file reset to resetLinesAndLocs() so line tables and the Location pool are reset together.
apps/oxlint/src-js/plugins/location.ts Implement Location pooling and update line/column helpers to populate objects in place.

@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_reduce_operations_in_binary_search branch from cea62d4 to 7de6e14 Compare March 21, 2026 12:21
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_recycle_location_objects branch from e627943 to 48e7129 Compare March 21, 2026 12:21
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_reduce_operations_in_binary_search branch from 7de6e14 to 2be5b0a Compare March 21, 2026 12:32
@overlookmotel overlookmotel force-pushed the om/03-18-perf_linter_plugins_recycle_location_objects branch from 48e7129 to 24da144 Compare March 21, 2026 12:32
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 21, 2026

Merge activity

Add an object pool for `Location` objects, and recycle them across files.

Usually, only a minority of AST nodes, tokens, and comments will have their `loc` property accessed, so the pool is not pre-populated - `Location` objects are only created on demand.

Like the other object pools, once warmed up over the first batch of files, the fast path for "use an existing object from the pool" will be consistently taken and no further objects will be allocated. All `Location` objects will soon graduate to "old space" where they don't impede or trigger minor GC.
@graphite-app graphite-app bot force-pushed the om/03-18-perf_linter_plugins_reduce_operations_in_binary_search branch from 2be5b0a to 8729614 Compare March 21, 2026 12:48
@graphite-app graphite-app bot force-pushed the om/03-18-perf_linter_plugins_recycle_location_objects branch from 24da144 to 5984a66 Compare March 21, 2026 12:49
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 21, 2026
Base automatically changed from om/03-18-perf_linter_plugins_reduce_operations_in_binary_search to main March 21, 2026 12:52
@graphite-app graphite-app bot merged commit 5984a66 into main Mar 21, 2026
24 checks passed
@graphite-app graphite-app bot deleted the om/03-18-perf_linter_plugins_recycle_location_objects branch March 21, 2026 12:53
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