Repository navigation
perf: read the .npmrc files once per config dir instead of per npm plugin - #1320
Merged
Merged
Conversation
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 was happening
Every npm plugin resolved through
PluginCache::resolve_registrywalked the.npmrcancestor chain twice: once for the registry (resolve_registry_without_proxy) and once for the proxy (resolve_npm_proxy), each ending with a separate read of~/.npmrceven when the home directory was already part of the walk. The registry cache inPluginCacheis keyed on package name, so it never helped across plugins. With the repo's 9npm:plugins and a warm cache,dprint output-file-pathsmade 162openatcalls for.npmrcfiles on this machine (9 plugins x 2 walks x 9 directories;$HOME/.npmrc36 times).What changed
NpmrcChaininnpm_resolution.rsreads the.npmrcfiles for a start dir once (ancestors nearest first, then~/.npmrcunless it was already an ancestor) and the registry, proxy andmin-release-agelookups all resolve from the loaded files, with the same precedence as before (first file setting a value wins,~/.npmrcis the fallback, env vars still win).PluginCachememoizes the loaded chain per config dir, so every npm plugin resolved from the same dir reuses it. The existing per-package registry cache stays so bad-credential warnings are still logged once.TestEnvironmentcounts file reads so tests can assert on them.Verification
cargo test -p dprint: all pass except the pre-existing umask-dependentextract_tarball_preserves_exec_bits_via_env_set_permissions. Two new tests assert each.npmrcis read once for a single resolve and once across several packages viaPluginCache.strace -f -e trace=openat dprint output-file-paths | grep -c npmrcon a warm cache: 162 before, 8 after (one per directory in the walk).