module: add persistent module resolution cache#63927
Open
watilde wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
Cache module resolution results on disk, enabled via NODE_MODULE_RESOLVE_CACHE=<dir> or module.enableModuleResolveCache(). Warm starts skip the node_modules search and package.json reads, cutting resolution time by ~36% (CJS) / ~34% (ESM) on a 1000-dep project. The binary cache is validated coarsely by a generation token (Node version, flags, lockfile signature) and respects the permission model. Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
29fa3dc to
8711c18
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an on-disk module resolution cache, enabled via
NODE_MODULE_RESOLVE_CACHE=<dir>ormodule.enableModuleResolveCache([dir])(mirroring the module compile cache). It persistsModule._pathCacheand the ESM resolver results so warm starts of fresh processes skip thenode_modulescandidate-stat search andpackage.jsonreads.Why
For apps with large dependency trees, module resolution (filesystem stats +
package.jsonreads) dominates startup. The compile cache addresses compilation but not resolution; this fills that gap.How
NODE_PATH, lockfile signature) → O(1) validation per process, not per dependency. Changing the lockfile rebuilds the cache.Impact
1000-dependency synthetic project, cold child process, wall median:
Tests / docs
test/parallel/test-module-resolve-cache.js(CJS + ESM, lockfile invalidation, API, disabled-by-default).benchmark/module/resolve-cache.js.doc/api/module.mdanddoc/api/cli.md.