perf: avoid quadratic sibling lookahead and per-function name slices in the CSS parser - #21520
Conversation
…in the CSS parser The walk now tracks each node's index within its sibling list (path.index) and exposes flat-span accessors (childCount/childAt), so the dashed-ident 'from' lookahead no longer materializes the sibling list and scans it per ident (~80x faster on a 4000-entry timeline-scope list). Function names are matched by byte range instead of slicing an unescaped copy per function node; only names carrying an escape pay the slice (~10% on function-dense CSS Modules).
🦋 Changeset detectedLatest commit: f3dbcfb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (3151fa6). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@3151fa6
yarn add -D webpack@https://pkg.pr.new/webpack@3151fa6
pnpm add -D webpack@https://pkg.pr.new/webpack@3151fa6 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21520 +/- ##
==========================================
+ Coverage 93.77% 93.79% +0.01%
==========================================
Files 620 620
Lines 73704 73761 +57
Branches 21262 21289 +27
==========================================
+ Hits 69116 69181 +65
+ Misses 4588 4580 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 6.11%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
640.1 KB | 1,205.4 KB | -46.9% |
| ⚡ | Memory | benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' |
9.3 MB | 7.3 MB | +27.54% |
| ⚡ | Memory | benchmark "cache-filesystem", scenario '{"name":"mode-production","mode":"production"}' |
4.9 MB | 4 MB | +22.22% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/css-parser-hot-paths (f3dbcfb) with main (8331267)
The walk now tracks each node's index within its sibling list (path.index) and exposes flat-span accessors (childCount/childAt), so the dashed-ident 'from' lookahead no longer materializes the sibling list and scans it per ident (~80x faster on a 4000-entry timeline-scope list). Function names are matched by byte range instead of slicing an unescaped copy per function node; only names carrying an escape pay the slice (~10% on function-dense CSS Modules).
Summary
What kind of change does this PR introduce?
Did you add tests for your changes?
Does this PR introduce a breaking change?
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Use of AI