Skip to content

perf: read the .npmrc files once per config dir instead of per npm plugin - #1320

Merged
dsherret merged 1 commit into
mainfrom
perf/npmrc-lookup-once
Oct 10, 2026
Merged

dsherret merged 1 commit into
mainfrom
perf/npmrc-lookup-once

Conversation

@dsherret

Copy link
Copy Markdown
Member

What was happening

Every npm plugin resolved through PluginCache::resolve_registry walked the .npmrc ancestor 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 ~/.npmrc even when the home directory was already part of the walk. The registry cache in PluginCache is keyed on package name, so it never helped across plugins. With the repo's 9 npm: plugins and a warm cache, dprint output-file-paths made 162 openat calls for .npmrc files on this machine (9 plugins x 2 walks x 9 directories; $HOME/.npmrc 36 times).

What changed

  • NpmrcChain in npm_resolution.rs reads the .npmrc files for a start dir once (ancestors nearest first, then ~/.npmrc unless it was already an ancestor) and the registry, proxy and min-release-age lookups all resolve from the loaded files, with the same precedence as before (first file setting a value wins, ~/.npmrc is the fallback, env vars still win).
  • PluginCache memoizes 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.
  • TestEnvironment counts file reads so tests can assert on them.

Verification

  • cargo test -p dprint: all pass except the pre-existing umask-dependent extract_tarball_preserves_exec_bits_via_env_set_permissions. Two new tests assert each .npmrc is read once for a single resolve and once across several packages via PluginCache.
  • strace -f -e trace=openat dprint output-file-paths | grep -c npmrc on a warm cache: 162 before, 8 after (one per directory in the walk).

@dsherret
dsherret merged commit 78d09ef into main Oct 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant