lib: bound the generated source map cache - #65761
Conversation
096455f to
0022ed5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65761 +/- ##
==========================================
+ Coverage 89.95% 90.06% +0.10%
==========================================
Files 759 769 +10
Lines 258637 261316 +2679
Branches 49015 49625 +610
==========================================
+ Hits 232665 235361 +2696
+ Misses 17018 16981 -37
- Partials 8954 8974 +20 🚀 New features to boost your workflow:
|
|
Thanks for the fast fix. Two points. Recency updates only on write.
The limit counts entries not bytes.Entry size follows the size of the mapped file. In the reported MDX case each entry is approximately 612 KB. 256 entries is then approximately 157 MB. In the synthetic repro each entry is approximately 415 KB, or approximately 106 MB. The ceiling changes with the user's largest generated file. Did you consider a byte budget? Minorthe test uses 300 against a limit of 256. Export the constant to keep the test correct. |
0022ed5 to
40865c5
Compare
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
40865c5 to
30748a2
Compare
|
All three applied in 30748a2. The cache now keeps a byte budget of 32 MiB instead of an entry count. Each entry is charged its source map url plus its line lengths, and the payload is added when it is resolved. The oldest entries go first, and the newest entry is always kept, so one large map can still be mapped on its own.
The limit is exported, and the test reads it to work out how many sources to evaluate. |
generatedSourceMapCachegrows for every evaluated source that carries a unique//# sourceURL, and nothing ever removes an entry. Unlike module sources, generated sources have no reachable script instance to key the cache weakly against, so code that re-evaluates the same file under a changing source url, which is what hot module replacement does, keeps every payload it ever mapped alive.Hold the least recently used generated source maps within a byte budget instead. Bytes rather than entries, because one map can carry hundreds of kilobytes of
sourcesContentwhile the next carries a handful. With the repro from the issue, retained heap settles at 40 MB rather than growing past 500 MB over 1200 evaluations.Fixes: #65760