fix(cache): replay missing_dependency tracking in cached_node_modules warm path#236
fix(cache): replay missing_dependency tracking in cached_node_modules warm path#236stormslowly wants to merge 2 commits into
Conversation
…warm hit When node_modules doesn't exist, the cold path adds the directory to ctx.missing_dependencies via module_directory -> is_dir. The warm cache early-return skipped this tracking, so webpack/rspack watchers would miss the signal to rebuild when a node_modules directory was later created. Mirrors the same replay pattern already applied to package_json in PR #224.
There was a problem hiding this comment.
Pull request overview
This PR fixes ResolveContext::missing_dependencies tracking on warm-cache hits for cached_node_modules, ensuring watcher-integrations (webpack/rspack) still receive “missing node_modules directory” signals after the resolver cache is populated.
Changes:
- Replay
ctx.add_missing_dependency(.../node_modules)oncached_node_modulescache hits when the cached result isNone. - Add a regression test asserting cold vs warm resolves produce identical
missing_dependencies, including absent traversednode_modulesdirectories.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/cache.rs |
Replays missing-dependency tracking on cached_node_modules warm-cache hits. |
src/tests/dependencies.rs |
Adds a regression test comparing cold vs warm missing_dependencies for absent node_modules dirs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codspeedbot explain why this is faster |
Based on my thorough flamegraph analysis, here's the explanation for the user. Since this is a comment response (no code changes needed), I'll provide the answer directly: Analysis SummaryAfter analyzing the CodSpeed flamegraphs for both the HEAD and BASE runs, comparing call trees, instruction counts, and the PR's code diff, here's what's happening: The 4.13% improvement is not directly caused by this PR's correctness fix. It's primarily attributable to PR #237 ( Evidence from the flamegraphs
PR #237 restructured the When comparing the two runs on this PR branch (before and after the merge with main), CodSpeed marks all 12 benchmarks as unchanged — confirming the improvement comes from the merge, not from this PR's What this PR actually doesThis PR's change — calling Summary
|
Why
PR #224 added early-return cache-hit guards to four
CachedPathhot accessors. Thepackage_jsonwarm path correctly replaysctx.add_file_dependency/ctx.add_missing_dependencyon cache hits, butcached_node_moduleswas missed.On the cold path,
cached_node_modules→module_directory→is_dircallsctx.add_missing_dependency(node_modules_path)when the directory doesn't exist. The early-return skipped this, so webpack/rspack file watchers wouldn't receive the signal to rebuild when anode_modulesdirectory was later created.What
Nonebranch of the warm-cache early-return, callctx.add_missing_dependency(self.path.join("node_modules"))— mirroring whatpackage_jsonalready does.missing_dependenciesis identical on both calls, with a spot-check against the two absentnode_modulespaths that enhanced-resolve explicitly tracks.Follow-up
A related cold-path divergence from enhanced-resolve was uncovered while validating this fix:
is_dirdoes not record a missing-dep when the path exists as a non-directory (e.g., a regular file namednode_modules). The warm path here happens to handle that case correctly because theOnceLock<Option<CachedPath>>folds "absent" and "non-dir" into the sameNone. Tracking the cold-path fix separately in #239.