perf(npm): optimize loading npm resolution snapshot from lockfile by only loading necessary version info #27261
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.
This is sort of a POC, the actual code is sus but works well enough to see the perf impact on real world projects.
Basically when we're loading the npm resolution snapshot from a lockfile, we read (and deserialize!) a bunch of
registry.json
files from the cache dir.The thing is, those
registry.json
files can be pretty massive (e.g. nextJS's registry.json is ~6MB), and reading and deserializing them is very expensive.We don't really need the entire
NpmPackageInfo
though, we just want the information for a specific version (the one in the lockfile).This PR optimizes this by creating an index of the registry.json files that gives the file offsets containing the version info for each version. Then, when we load the snapshot we read the index to get the byte offsets for the version we need, and only load (and deserialize) that part of the
registry.json
file.Results (this is in a project from create-next-app)
Running an empty file with
--node-modules-dir=auto
(which eagerly loads the resolution snapshot):Deno install with a populated cache dir, but setting up node modules from scratch:
A no-op deno install (node_modules already set up):