Commit 4ee80ac
committed
perf(linter/plugins): remove bounds checks on regex tokens (#20478)
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!1 parent c3d9e91 commit 4ee80ac
1 file changed
+5
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
399 | 402 | | |
400 | 403 | | |
401 | | - | |
| 404 | + | |
402 | 405 | | |
403 | 406 | | |
404 | 407 | | |
| |||
0 commit comments