perf(linter/plugins): reduce allocations for tokens and comments with accessed loc#20480
Merged
graphite-app[bot] merged 1 commit intomainfrom Mar 21, 2026
Conversation
This was referenced Mar 17, 2026
Member
Author
This was referenced Mar 17, 2026
5e9ff3a to
c659d44
Compare
9e16a5a to
9254068
Compare
This was referenced Mar 18, 2026
c659d44 to
66d228c
Compare
9254068 to
1c54851
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces per-file allocations in oxlint’s JS-side token/comment infrastructure by keeping the “loc-accessed” tracking arrays at a stable capacity and using an active-count cursor instead of shrinking them to length 0 between files.
Changes:
- Track tokens/comments whose
locwas accessed viaactiveTokensWithLocCount/activeCommentsWithLocCount. - Avoid
array.length = 0on reset; reuse existing backing stores by resetting only the active counters. - Update reset loops to iterate only over the active portion of each tracking array.
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/tokens.ts | Reuses tokensWithLoc backing store across files with an active-count cursor; updates reset logic accordingly. |
| apps/oxlint/src-js/plugins/comments.ts | Mirrors the same active-count approach for commentsWithLoc and updates reset logic. |
66d228c to
847014b
Compare
1c54851 to
7c469ec
Compare
This was referenced Mar 18, 2026
This was referenced Mar 19, 2026
Contributor
Merge activity
|
847014b to
d825833
Compare
3426e69 to
dfd5e3f
Compare
d825833 to
72d4da3
Compare
… accessed `loc` (#20480) Similar to #20479. `tokensWithLoc` and `commentsWithLoc` contain tokens/comments on which `loc` property has been accessed. Previously these arrays were grown with `.push(token)`, and shrunk at end of linting file with `tokensWithLoc.length = 0;`. Problem with that is that setting length to 0 frees the array's backing allocation, which means it has to reallocate again on next file when a token's `loc` is accessed. Instead, never shrink these arrays, and track the active length in separate variables. After warm-up over first batch of files, these arrays will graduate to "old space" and just sit there without further allocations. Unlike #20479, we don't use `Uint32Array`s as `loc` is calculated lazily, and `Token`'s / `Comment`s don't know what their index is in the `cachedTokens` / `cachedComments` arrays. Adding an `#index` field to `Token` and `Comment` would bloat every instance of these classes by 8 bytes.
graphite-app bot
pushed a commit
that referenced
this pull request
Mar 21, 2026
Possibly the most absurd optimization I've ever encountered.
```diff
- if (regexObjects.length > regexIndex) {
+ if (regexIndex < regexObjects.length) {
regex = regexObjects[regexIndex];
}
```
There is no semantic difference whatsoever between `regexObjects.length > regexIndex` and `regexIndex < regexObjects.length`. But V8's 2nd-tier Maglev compiler treats them differently. In the`>` version, `regexObjects[regexIndex]` incurs a bounds check, whereas in the new `<` version, no bounds check.
This is a micro-optimization, but this function is extremely hot, so it may actually move the needle in code that includes a lot of regexes. The same optimization is also applied in #20480.
Claude found this oddity by reading V8's source code!
dfd5e3f to
9c7a267
Compare
72d4da3 to
9cfc312
Compare
Base automatically changed from
om/03-17-perf_linter_plugins_reduce_allocations_for_regex_tokens
to
main
March 21, 2026 12:51
This was referenced Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Similar to #20479.
tokensWithLocandcommentsWithLoccontain tokens/comments on whichlocproperty has been accessed.Previously these arrays were grown with
.push(token), and shrunk at end of linting file withtokensWithLoc.length = 0;. Problem with that is that setting length to 0 frees the array's backing allocation, which means it has to reallocate again on next file when a token'slocis accessed.Instead, never shrink these arrays, and track the active length in separate variables. After warm-up over first batch of files, these arrays will graduate to "old space" and just sit there without further allocations.
Unlike #20479, we don't use
Uint32Arrays aslocis calculated lazily, andToken's /Comments don't know what their index is in thecachedTokens/cachedCommentsarrays. Adding an#indexfield toTokenandCommentwould bloat every instance of these classes by 8 bytes.