perf: shrink the persistent cache#21210
Conversation
🦋 Changeset detectedLatest commit: 72ee8be 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 (d2b730d). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@d2b730d
yarn add -D webpack@https://pkg.pr.new/webpack@d2b730d
pnpm add -D webpack@https://pkg.pr.new/webpack@d2b730d |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21210 +/- ##
==========================================
- Coverage 92.69% 92.67% -0.02%
==========================================
Files 588 591 +3
Lines 64122 64326 +204
Branches 17799 17872 +73
==========================================
+ Hits 59435 59614 +179
- Misses 4687 4712 +25
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 improve performance by 74.11%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
129.3 KB | 361.4 KB | -64.22% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
858.9 KB | 124.2 KB | ×6.9 |
| ⚡ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,301.4 KB | 318.4 KB | ×4.1 |
| ⚡ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
319.6 KB | 247.2 KB | +29.29% |
| ⚡ | Memory | benchmark "wasm-modules-sync", scenario '{"name":"mode-production","mode":"production"}' |
7.7 MB | 6.3 MB | +22.34% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing pref-cache-size (72ee8be) with main (6e43ab8)
…of larger far back-references
|
Measured on the 10,000-module benchmark (controlled A/B, identical input, no cache.compression): total pack |
Summary
What kind of change does this PR introduce?
Two serializer changes that shrink the persistent cache, so cache files read and deserialize faster:
BinaryMiddleware: add a fusedNULL_AND_I16header (free byte0x19). Back-references are written as null + a relative offset; offsets that overflow an i8previously fell straight toi32(5 bytes) even though most fit ani16. They now pack into 3 bytes. Thei8/i32/f64number-run prefixes are exhausted, so this targets the dominant null-prefixed reference path rather than a generali16run.ObjectMiddleware: when a string back-reference would be a 5-bytei32, inline the string instead if it's a tiny single-byte 2–3 char string (1 + length bytes is smaller). The-32768threshold accounts for the newi16tier so references in the 3-byte band are kept. The string is re-registered at the closer position, and since the deserializer already re-registers every inline length > 1 string, reference positions stay in sync and the on-disk format is unchanged.Did you add tests for your changes?
No
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Yes