perf(linter/plugins): remove bounds checks on regex tokens#20478
Merged
graphite-app[bot] merged 1 commit intomainfrom Mar 21, 2026
Merged
Conversation
This was referenced Mar 17, 2026
Member
Author
This was referenced Mar 17, 2026
0eb994b to
7b220af
Compare
66d4271 to
208bee0
Compare
This was referenced Mar 18, 2026
7b220af to
f7bf3dc
Compare
208bee0 to
5374681
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies a micro-optimization in the hot token deserialization path by rewriting a regex-cache bounds comparison into a form that V8/Maglev can use to elide an array bounds check.
Changes:
- Swaps the regex cache guard from
regexObjects.length > regexIndextoregexIndex < regexObjects.lengthto enable Maglev bounds-check elimination. - Updates the surrounding comment to document the V8-specific rationale and constraint.
This was referenced Mar 18, 2026
This was referenced Mar 19, 2026
5374681 to
2090432
Compare
f7bf3dc to
1d06d2c
Compare
2090432 to
94eb885
Compare
1d06d2c to
c00f3e6
Compare
Contributor
Merge activity
|
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!
c00f3e6 to
c3d9e91
Compare
94eb885 to
4ee80ac
Compare
Base automatically changed from
om/03-17-fix_linter_plugins_fix_memory_leak_in_tokens_and_comments
to
main
March 21, 2026 12:50
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.

Possibly the most absurd optimization I've ever encountered.
There is no semantic difference whatsoever between
regexObjects.length > regexIndexandregexIndex < 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!