Latest Results
feat: add parsedMap option, post-minifier benchmark, getCachedData test
Addresses the polish items from the second review of PR #221:
- **#2 post-minifier asset shape benchmark.** New Scenario 3 in
`benchmark/memory/clear-cache.mjs` constructs the shape webpack
assets actually present at the PROCESS_ASSETS_STAGE_DEV_TOOLING
hook: a `CachedSource` wrapping a `SourceMapSource` whose
`_cachedSource` (bundle string) and `_cachedMaps[{}]` (composed
map) are populated. 50 chunks: 8.5 MB baseline → 0 MB after
`clearCache({ maps: true, source: false, recursive: false })`.
- **#3 optional `parsedMap: true` flag** on `ClearCacheOptions`.
When set, `SourceMapSource.clearCache` drops the parsed object
forms of `_sourceMapAsObject` and `_innerSourceMapAsObject`
(heaviest cached representation), but only when a serialized form
(buffer or string) is also held so data stays recoverable.
Defaults to `false` to preserve the cheap toString re-hydration
path described in the comment.
- **#4 `getCachedData()` after `clearCache()` interaction test.**
Pins the observable shape: buffer + source = undefined, maps
empty, hash + size preserved when their flags default to false.
Round-trips through `new CachedSource(source, data)` to confirm
cleared cached data is still a valid input.
- **#5 "release hint" framing** in the `Source.prototype.clearCache`
JSDoc. Opens with "clearCache is a memory hint: it never affects
correctness or output, only how expensive the next read is."
- **#6 dedup correctness test** already lives at
`test/clearCache.js:251` ("a shared subtree is walked once when
a `visited` WeakSet is passed") with a negative control at :269.
Tests grow to 25 (was 22). Full suite 89,870/89,870 pass, lint
clean. Benchmark numbers unchanged on Scenarios 1 + 2: 44.7%
heap reduction on unique tasks, 3.6× dedup speedup, 228×
`recursive: false` speedup.
https://claude.ai/code/session_01LLtSGKaynui1P1wQsfVnXxclaude/fix-webpack-issue-0KinR feat: deduplicate clearCache recursion and add granular options
Review of PR #221 flagged three blocking issues for webpack's
SourceMapDevToolPlugin use case:
1. **Recursion had no de-duplication.** When a webpack plugin iterates
assets, the same module-level CachedSource is reachable from many
chunks, so calling `clearCache()` per asset re-walked the shared
subtree once per chunk. The reviewer's 50-chunk benchmark went from
10s to 17–45s with no extra heap freed.
2. **Recursion was non-opt-outable.** Webpack often replaces the asset
shortly after calling `clearCache()`, so walking the children
ourselves is pure waste — V8 reclaims them for free anyway.
3. **Cheap-to-hold caches were cleared unconditionally.**
`_cachedSize` is a single number; `_cachedHashUpdate` is what makes
downstream `cache.store` cheap. Dropping them on a generic
"release memory" call is a perf cliff.
The new signature addresses all three:
```js
clearCache(
{ maps = true, source = true, hash = false, size = false,
recursive = true } = {},
visited
)
```
- A `visited` `WeakSet` lets callers iterate assets in a loop and walk
each shared subtree at most once. Internally, every node also adds
itself to `visited` on first visit so further parents short-circuit.
- `recursive: false` makes the call O(1) per asset for the common case
where the asset is about to be GC'd anyway.
- `hash` and `size` default to `false` (kept) — they're cheap to hold
and expensive to rebuild.
- `_cachedMaps.clear()` replaces `new Map()` to avoid per-call
allocation churn.
Updated benchmark (`benchmark/memory/clear-cache.mjs`) adds a
shared-modules scenario mirroring the reviewer's webpack shape. On 50
chunks × 1000 shared modules:
- naive `clearCache()` 12.7 ms
- `clearCache(opts, visited)` 4.4 ms (2.9× speedup)
- `clearCache({ recursive: false })` 0.1 ms (188× speedup)
`CompatSource.clearCache` now forwards `visited` through to wrapped
SourceLike implementations so dedup is preserved across CompatSource
boundaries. Public `Source.prototype.clearCache` JSDoc documents the
concurrency contract and that subsequent reader calls may repopulate
caches.
Tests grow to 22 (was 14) — covers dedup, the granular options, the
opt-out recursion, and that `_cachedMaps` is reused not reallocated.
https://claude.ai/code/session_01LLtSGKaynui1P1wQsfVnXxclaude/fix-webpack-issue-0KinR Latest Branches
0%
claude/fix-webpack-issue-0KinR 0%
dependabot/github_actions/dependencies-f42450c4f3 0%
dependabot/npm_and_yarn/fast-uri-3.1.2 © 2026 CodSpeed Technology