Repository navigation
Commit ef7223f
authored
perf(javascript): read a regexp repeating a capture group name in linear time (#22187)
* test(javascript): hold the parser to acorn's own test suite
acorn ships no tests in its npm tarball, so `WebpackParser.unittest.js` records
them itself: it replays every `test/tests*.js` of an acorn checkout against a
driver that records rather than parses, and vendors each case's source, options
and expected error as `test/fixtures/acorn-corpus.json`. The expected trees are
left behind — the run takes those from acorn itself.
All 3534 cases go through both parser entry points under three option sets,
diffing trees, comments, tokens and error messages against acorn and
re-asserting acorn's own recorded verdicts. Where the checkout exists the run
also checks the corpus against it, and `WEBPACK_UPDATE_ACORN_CORPUS=1` rewrites
it. The tree diff moves to `test/helpers/compareParserOutput.js`, shared with
the test262 suite.
* perf(javascript): read a regexp repeating a capture group name in linear time
Validating a named capture group compares its branch against every branch
already recorded for that name, and acorn compares two branches by walking one
chain per node of the other — quadratic in the nesting depth, per pair. A
pattern of 160 alternatives each nesting a same-named group 160 deep took
7.4s where the same pattern with distinct names took 0.09s.
A branch chain holds at most one branch per disjunction, so marking each
disjunction the first chain passed answers the comparison in one walk of the
second. The same pattern now validates in 0.12s (acornjs/acorn#1445).
* test(javascript): ask the engine which regexps it read, not a list
The corpus exempted a fixed list of patterns from the verdict comparison: the
ones acorn rejects by edition that webpack takes as written because the host
engine built them. Which patterns those are is the running V8's answer, so a
newer one reads more of them and the list went stale — CI's V8 accepts ES2025
duplicate capture names and modifier groups, and 38 cases diverged there that
agree here.
The exemption now reads the tree webpack returned: a regexp literal the engine
built carries a real RegExp as its value. The ported base parser, which
validates every literal, is held to acorn with no exemption at all.
* style(javascript): shorten the comment over the branch marking
Two lines, as the lib/ review instruction asks, keeping what the code cannot
say: a chain holds one branch per disjunction, and acorn nests the walk.
* test(javascript): let the runtime decide how deep the corpus may nest
acorn records `~Not enough stack space` for its deeply nested case, and the
comparison allowed for the two parsers reaching that depth a few frames apart.
It did not allow for a runtime reaching it on neither side: under Bun both
parse the case, so the recorded expectation goes unmet and the verdicts differ
from acorn's on V8.
Stack depth is the runtime's answer rather than the parser's, so a verdict or
a recorded expectation naming it is left alone on either side.1 parent d38be99 commit ef7223f
10 files changed
Lines changed: 4317 additions & 98 deletions
File tree
- .changeset
- lib/javascript
- test
- fixtures
- helpers
- specCases
- unitCases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
57 | 70 | | |
58 | 71 | | |
59 | 72 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 73 | + | |
| 74 | + | |
66 | 75 | | |
67 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
68 | 86 | | |
69 | 87 | | |
70 | 88 | | |
| |||
0 commit comments