Repository navigation
fix: skip re-importing packages when global virtual store is warm - #10709
Conversation
When node_modules is deleted but the global virtual store directories survive, pnpm previously re-fetched every package because the skip logic required currentLockfile to be present. Add a fast-path that checks pathExists(dir) for GVS directories even when currentLockfile is missing, since the GVS directory hash encodes engine, integrity, and full dependency subgraph.
|
💖 Thanks for opening this pull request! 💖 |
There was a problem hiding this comment.
Pull request overview
This PR optimizes installs when using pnpm’s global virtual store by avoiding unnecessary package re-imports after node_modules is deleted but the global virtual store directories remain present (“warm”), and adds a regression test plus a changeset entry.
Changes:
- Add a “reattach” fast-path in
lockfileToDepGraphto skip fetching/importing when the computed global virtual store package directory already exists. - Add an install test that deletes only
node_modulesand reinstalls withfrozenLockfile. - Add a changeset documenting the patch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
deps/graph-builder/src/lockfileToDepGraph.ts |
Adds a new warm-global-store existence check to set fetchResponse = {} and avoid re-import. |
pkg-manager/core/test/install/globalVirtualStore.ts |
Adds a test case for reinstalling after deleting only node_modules while keeping the global virtual store. |
.changeset/global-virtual-store-reattach.md |
Declares patch releases and describes the behavior change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The includeUnchangedDeps flag is true whenever currentHoistPattern
differs from the desired hoistPattern. After deleting node_modules,
currentHoistPattern is always undefined (read from .modules.yaml),
so the flag is always true when hoisting is configured — defeating
the optimization in the exact scenario it targets.
The guard is unnecessary because the fast-path only skips fetch/import
(fetchResponse = {}), not graph inclusion. The package is still added
to the graph with children populated, so hoisting recalculation works.
Adds benchmark 6: frozen lockfile reinstall with a warm global virtual store after deleting node_modules. This measures the reattach fast-path where all packages are skipped (no fetch/import) because their GVS hash directories already exist.
5ce02a5 to
eba438a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
That's awesome! |
|
I wonder if the same issue is present during non-headless install. |
Problem
When
node_modulesis deleted but the global virtual store ({storeDir}/links/) remains intact, pnpm re-imports every package from the content-addressable store — even though the materialized package directories already exist globally.The root cause: the skip logic in
lockfileToDepGraph.tsdepends oncurrentLockfile(fromnode_modules/.pnpm/lock.yaml). Whennode_modulesis deleted,currentLockfileisnull,currentPackages = {},depIsPresentis alwaysfalse, and both skip paths are unreachable. Every package falls through tofetchPackage().With the standard (local) virtual store this is unavoidable —
dirpoints insidenode_moduleswhich was deleted. But with the global virtual store,dirpoints to{storeDir}/links/{hash}/...— a path outsidenode_modulesthat survives deletion. ThepathExists(dir)check would succeed if it were reached, but it never is.Solution
Add a reattach fast-path after the existing skip blocks, before the
fetchPackagefallback:Why this is safe
The global virtual store directory path is the integrity check. The
depGraphHashin the path encodes:pkgIdWithPatchHash + resolution.integrityIf any of these change, the hash changes, the path changes, and
pathExistsfails. Directory existence is a constructive proof of validity.Guard conditions
!fetchResponseopts.enableGlobalVirtualStore!isDirectoryDepfile:protocol packages!opts.force--forceshould bypass all skip logicWhat
fetchResponse = {}does downstreamThis is the same pattern used by the existing secondary skip (line 253):
Benchmark Results
Measured with
benchmarks/bench.sh(5 runs, 1 warmup, fixture package with ~200 deps):No regressions on any existing scenario. GVS warm reinstall goes from 5.1s to 695ms — a 7.4x speedup.
Related issues
Test plan
node_modules(keep global store warm) → reinstall withfrozenLockfile: true→ verifynode_modulesrecreated correctlyfetchPackageconfirms 0 calls during warm reinstall (fast-path actually fires)globalVirtualStoretests pass