GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: narrow purge for watched directories in NodeWatchFileSystem by alexander-akait · Pull Request #21020 · webpack/webpack Conversation
Member
Watchpack reports a watched directory (a context dependency) in For directories we explicitly watch, invalidate only the directory's own Single-file rebuilds on a local 4000-file context drop from ~370 ms to Closes #13636
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Watchpack reports a watched directory (a context dependency) in `changes` whenever its contents change, alongside the individual file events. `inputFileSystem.purge(dir)` uses `key.startsWith(dir)` internally, so calling it on the directory wiped the stat cache of every file inside, even though only file-level events actually invalidate file stats. `ContextModuleFactory.resolveDependencies` then re-stat-ed every file in the tree on every incremental rebuild. For directories we explicitly watch, invalidate only the directory's own `readdir` entry; file-level changes in the same aggregated event continue to purge file stats and the parent `readdir` (via `purgeParent`) as before, so adds, removes, modifies and nested changes are still detected. Single-file rebuilds on a local 4000-file context drop from ~370 ms to ~225 ms (~40%). Closes #13636 …actory `ContextModuleFactory.resolveDependencies` previously fired the `alternativeRequests` hook once per file with a single-item array, paying per-call overhead (closure allocation, `compiler.resolverFactory.get(...)` lookup, intermediate array allocations inside `RequireContextPlugin`'s tap) for every file in the context. Collect all matched files per directory walk and invoke the hook once with the full batch; the existing tap already iterates the items array so the output is unchanged. Trims a further ~15 ms from steady-state rebuilds on a 4000-file `require.context` workload. …TED_ANY Replace the `/** @type {EXPECTED_ANY} */ (fs)._readdirBackend` cast in `NodeWatchFileSystem`'s narrow-purge path with a local `CacheBackend` typedef and an `InputFileSystemWithBackends` augmented file-system type, so the private backend slot we read off enhanced-resolve's `CachedInputFileSystem` is described precisely instead of widened to `any`. No behavior change. …o _readdirBackend Replace the private `_readdirBackend.purge(item)` access with the public unified API added in [email protected]: fs.purge(item, { exact: true }) This invalidates only the exact key across every backend (stat, lstat, readdir, readlink, realpath, readFile, readJson) without removing cached entries for descendants — the same semantics the previous _readdirBackend probe was approximating, but expressed as the consumer-facing API rather than a private slot. Drops the CacheBackend / InputFileSystemWithBackends JSDoc typedefs that only existed to type the private access, and bumps the enhanced-resolve peer to ^5.22.0. Performance characteristic is unchanged: median single-file rebuild on a 4000-file watched context is ~650 ms vs ~1260 ms without narrowing (≈49% local reproduction). Lockfile update following the package.json bump to ^5.22.0, which
introduced the { exact: true } option on CachedInputFileSystem#purge
consumed by NodeWatchFileSystem.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
🦋 Changeset detectedLatest commit: e8cb5a2 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
This PR is packaged and the instant preview is available (a086147). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@a086147
yarn add -D webpack@https://pkg.pr.new/webpack@a086147
pnpm add -D webpack@https://pkg.pr.new/webpack@a086147 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## main #21020 +/- ## ======================================= Coverage 91.57% 91.57% ======================================= Files 573 573 Lines 59460 59465 +5 Branches 16054 16058 +4 ======================================= + Hits 54449 54458 +9 + Misses 5011 5007 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Improves watch-mode incremental rebuild performance for large context dependencies by avoiding overly broad filesystem cache invalidation and reducing per-file hook-call overhead in context dependency resolution.
Changes:
inputFileSystem.purge() invalidation for explicitly watched context directories by using { exact: true } (enhanced-resolve ≥ 5.22.0) in NodeWatchFileSystem.ContextModuleFactory’s alternativeRequests hook invocation per directory instead of per file to reduce overhead.enhanced-resolve to ^5.22.0 and update filesystem purge typings/documentation accordingly; add changesets for release notes.Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/node/NodeWatchFileSystem.js |
Purges watched directories with { exact: true } to avoid wiping descendant stat cache on directory change events. |
lib/ContextModuleFactory.js |
Batches alternativeRequests hook calls per directory to cut per-file overhead during context resolution. |
lib/util/fs.js |
Extends Purge typedef docs/signature to include optional { exact?: boolean }. |
package.json |
Updates enhanced-resolve dependency to ^5.22.0. |
yarn.lock |
Locks enhanced-resolve to 5.22.0. |
types.d.ts |
Updates generated InputFileSystem.purge type signature to accept optional { exact?: boolean }. |
.changeset/watch-narrow-purge-context-dir.md |
Adds changeset entry for the watch-mode purge narrowing performance fix. |
.changeset/batch-alternative-requests.md |
Adds changeset entry for batching alternativeRequests performance improvement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
enhanced-resolve 5.22.0 introduced a CompiledAliasOptions typedef (in AliasUtils.js) referenced transitively via TsconfigPathsData.alias. yarn fix:special picks it up; CI's lint:special job requires the regenerated file to be committed.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Types CoverageCoverage after merging claude/fix-issue-13636-ts24Z into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Restore the exact purge of #21020 and pass readdirPrefix so cached readdir results under a changed context directory are read again.
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> **Summary** <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> <!-- Try to link to an open issue for more information. --> <!-- Any other information related to changes. --> Needed for webpack/webpack#23281. webpack's watcher purges a changed context directory with `{ exact: true }`, so the file stats below it stay cached (webpack/webpack#21020). But the cached `readdir` of its subdirectories stays too, so a file added in `pages/sub/` is never listed. A plain prefix purge fixes that but drops every stat below the directory again. `readdirPrefix: true` keeps `exact` for every cache but `readdir`, which is purged by prefix. The `readdir` cache holds one entry per directory, so the extra scan is small. ```js fs.purge("/app/pages", { exact: true, readdirPrefix: true }); // readdir("/app/pages/sub") -> read again // stat("/app/pages/sub/existing.js") -> still cached ``` <!-- In addition to that please answer these questions: --> **What kind of change does this PR introduce?** <!-- E.g. a fix, feat, refactor, perf, test, chore, ci, build, style, revert, docs or describe it if you did not find a suitable kind of change. --> feat **Did you add tests for your changes?** <!-- Please note: in most cases, if you change the code, we will not merge your changes unless you add tests. --> Yes: `test/CachedInputFileSystem.test.js` ("should prefix-purge readdir but keep stats with readdirPrefix: true"), failing without the change. **Does this PR introduce a breaking change?** <!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. --> No. The option is new and off by default. **If relevant, what needs to be documented once your changes are merged or what have you already documented?** <!-- List all the information that needs to be added to the documentation after merge that has already been documented in this PR. --> JSDoc and `types/CachedInputFileSystem.d.ts` updated; changeset added. **Use of AI** <!-- If you have used AI, please state so here. Explain how you used it. Make sure to read our AI policy (https://github.com/webpack/governance/blob/main/AI_POLICY.md) or your Pull Request may be closed due to irresponsible use of AI. --> Claude Code designed the option, wrote the change, test and changeset, and checked it against webpack's watch test with this patch linked in. --- _Generated by [Claude Code](https://claude.ai/code/session_013FhutRJzrgNvFy8wBC9JZm)_ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added an option to purge cached directory listings beneath a specified path while retaining exact-match purging for other cached data. * **Documentation** * Documented the new cache-purge option and its behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ext (#23285) * fix(watch): pick up files added in a subdirectory of a recursive context Purge a changed watched directory by prefix again, so cached readdir results of its subdirectories are dropped. Reverts the lib/ part of #21020. Fixes #23281 * fix(watch): keep exact directory purge, drop listings below it Restore the exact purge of #21020 and pass readdirPrefix so cached readdir results under a changed context directory are read again. * chore(deps): bump enhanced-resolve to 5.27.0 for purge readdirPrefix
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
perf problems withrequire.context
There was an error while loading. Please reload this page.