Repository navigation
fix: cache unsuccessful hosted Git URL parses - #347
Merged
Merged
Conversation
Keep failed parses in the bounded LRU with an internal null sentinel, preserve undefined returns, and invalidate cached results when registering hosts. Cover negative-hit recency and mixed-result eviction. Co-authored-by: Copilot <[email protected]>
jeffwidman
commented
Oct 15, 2026
jeffwidman
marked this pull request as ready for review
October 15, 2026 06:18
nkolev92
approved these changes
Oct 29, 2026
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to cache failed parses of unsupported hosted Git inputs.
No open issues 🎉
What changed in this PR
This PR avoids repeated parsing of unsupported hosted Git inputs by caching failures in the existing bounded LRU cache, while preserving the public undefined return value.
Changes:
- Store failed parses as internal
nullentries and clear the cache when a host is registered. - Add tests for failure reuse, shared capacity, recency, eviction, successful-result reuse, and host-registration invalidation.
- Correct the README to document the existing
undefinedreturn behavior.
| File | Description |
|---|---|
test/invalid.js |
Tests negative caching, LRU behavior, and host-registration invalidation. |
README.md |
Corrects the documented return value for unmatched URLs. |
lib/index.js |
Caches failed parses and invalidates cached results on host registration. |
Review effort: Balanced
jeffkl
approved these changes
Oct 29, 2026
martinrrm
pushed a commit
to npm/cli
that referenced
this pull request
Nov 11, 2026
<!-- What / Why --> <!-- Describe the request in detail. What it does and why it's being changed. --> Skip the no-op body of named-edge refresh for nodes with no outgoing dependencies and no children. ### Why While constructing a virtual dependency tree, adding or moving a package refreshes named edges through existing descendants. An empty leaf cannot have an edge to refresh or a descendant to visit, yet it still performs a case-insensitive lookup and enters both child loops. Return immediately only when `edgesOut`, `children`, and `fsChildren` are all empty. This does not cache emptiness: later dependency or child additions remain visible. Nodes without outgoing dependencies but with package or filesystem children must still be traversed. The traversal still calls the method for empty leaves; this skips its unnecessary body rather than changing the algorithm's asymptotic complexity. There is no new cache, index, deferred resolution, or intended public API/output change. Regression tests verify that an empty leaf performs no edge lookup, that adding dependencies later restores normal refresh behavior, and that dependency-free parents still refresh both package and filesystem descendants when targets are added or removed. ### Performance In an offline large-workspace native npm benchmark: | Flow | Median CPU, before -> after | Median wall, before -> after | | --- | --- | --- | | Lockfile writer | 6.389 -> 5.815 s (**9.0% lower**) | 5.325 -> 4.675 s (**12.2% lower**) | | Dry-run checker | 5.712 -> 5.063 s (**11.4% lower**) | 4.724 -> 4.022 s (**14.9% lower**) | The baseline already contains runtime adaptations of #10127, #10128, npm/hosted-git-info#347, and #10130; the candidate adds only this early return. This branch is independently based on `latest`, not stacked on those PRs. Method: Node 24.22.0, npm 11.17.0 / Arborist 9.8.0, networking disabled, 4 CPUs / 12 GB, one excluded warmup per arm and three alternating measured pairs. Writer uses `--package-lock-only --force --ignore-scripts`; checker uses `--package-lock-only --dry-run=true --ignore-scripts`; both additionally disable audit/funding and use `--offline --timing`. All compared manifests, lockfiles (including the writer's hidden lockfile), configuration files, and normalized logs were identical. Separate instrumentation avoided **3,997,148 empty-leaf map lookups**, reducing total map gets from **9,439,354 to 5,442,206**. A public synthetic tree with 128 dependency-free packages reduced map gets from **8,512 to 256**, with the same children and inventory. **Savings overlap the canonical-ASCII map normalization fast path in #10132.** A separate five-pair comparison after that fast path still measured: - Writer CPU **5.375 -> 5.231 s (2.7% lower)**; wall **4.223 -> 4.022 s (4.8% lower)**. - Checker CPU **4.679 -> 4.440 s (5.1% lower)**; wall **3.672 -> 3.421 s (6.8% lower)**. Do not add the standalone percentages together. Tiny seven-pair controls were roughly neutral (standalone CPU -1.5%, wall +0.1%; after the ASCII fast path CPU -0.9%, wall -0.4%). These are workload-specific native-command measurements, not a universal regression-free claim or complete Dependabot job savings. ### Validation On this standalone branch, based on npm 12.2.0 / Arborist 10.0.3, using existing development dependencies: - `node bin/npm-cli.js test --workspace=@npmcli/arborist --ignore-scripts -- --jobs=4` — **passed all 59 test files; 100% statements, branches, functions, and lines**. - `eslint workspaces/arborist/lib/node.js workspaces/arborist/test/node.js` — **passed**. - `git diff --check` — **passed**. No snapshots were changed. During the preceding investigation, an additional 24-command offline workspace/lockfile-version matrix passed with this optimization and the ASCII fast path together; the full suite above was rerun with this optimization alone. The full npm CLI suite and Windows/macOS runs were not performed. ## References <!-- Examples: Related to #0 Depends on #0 Blocked by #0 Fixes #0 Closes #0 --> Related independent native-work reductions: #10127, #10128, npm/hosted-git-info#347, #10130. The related normalization fast path is proposed independently in #10132. Neither PR depends on the other. --------- Co-authored-by: Copilot <[email protected]>
martinrrm
pushed a commit
to npm/cli
that referenced
this pull request
Nov 11, 2026
<!-- What / Why --> <!-- Describe the request in detail. What it does and why it's being changed. --> Skip Unicode normalization and case folding for case-insensitive map keys that are already canonical ASCII. ### Why Loading a large workspace lockfile repeatedly refreshes named dependency edges. Those traversals perform millions of case-insensitive map lookups, mostly misses. Normalizing every lookup key is expensive even when the name contains only lowercase ASCII, digits, and punctuation. This adds a cache-free fast path: ASCII strings without uppercase letters are unchanged by both NFKD normalization and `toLowerCase()`, so return them directly. Uppercase or non-ASCII strings retain the existing normalization path, including surrogate pairs and compatibility characters. Non-string keys retain their existing behavior. No changes to map storage, key replacement, iteration order, or dependency resolution are intended. Tests cover case/Unicode-equivalent keys, compatibility characters, supplementary-plane characters, replacement/deletion, empty strings, undefined values, and non-string keys. ### Performance In an offline large-workspace native npm benchmark: | Flow | Median CPU, before -> after | Median wall, before -> after | | --- | --- | --- | | Lockfile writer | 6.389 -> 5.286 s (**17.3% lower**) | 5.325 -> 4.124 s (**22.6% lower**) | | Dry-run checker | 5.712 -> 4.527 s (**20.8% lower**) | 4.724 -> 3.621 s (**23.3% lower**) | The baseline already contains runtime adaptations of #10127, #10128, npm/hosted-git-info#347, and #10130; the candidate adds only this fast path. These are incremental native-command measurements, not savings versus unmodified npm or end-to-end Dependabot job savings. This branch itself is independently based on `latest`, not stacked on those PRs. Method: Node 24.22.0, npm 11.17.0 / Arborist 9.8.0, networking disabled, 4 CPUs / 12 GB, one excluded warmup per arm and three alternating measured pairs. Writer uses `--package-lock-only --force --ignore-scripts`; checker uses `--package-lock-only --dry-run=true --ignore-scripts`; both additionally disable audit/funding and use `--offline --timing`. All compared manifests, lockfiles (including the writer's hidden lockfile), configuration files, and normalized logs were identical. Separate instrumentation reduced NFKD calls during the writer from **9,650,439 to 1,054**. On a public synthetic tree of 128 dependency-free packages, NFKD calls fell from **8,640 to zero**. A tiny local-dependency control over 21 pairs found no conclusive difference: paired-median CPU change +0.05%, wall -0.58%; bootstrap 95% intervals crossed zero. This is not a universal regression-free claim. ### Validation On this standalone branch, based on npm 12.2.0 / Arborist 10.0.3, using existing development dependencies: - `node bin/npm-cli.js test --workspace=@npmcli/arborist --ignore-scripts -- --jobs=4` — **passed all 59 test files; 100% statements, branches, functions, and lines**. - `eslint workspaces/arborist/lib/case-insensitive-map.js workspaces/arborist/test/case-insensitive-map.js` — **passed**. - `git diff --check` — **passed**. A separate differential harness rechecked the final publication source against the original map: all **1,114,112 code-point values**, 10,000 mixed strings, and 20,000 mutation operations matched, including key collisions, iteration order, non-string keys, and clear/delete operations. No snapshots were changed. The full npm CLI suite and Windows/macOS runs were not performed. ## References <!-- Examples: Related to #0 Depends on #0 Blocked by #0 Fixes #0 Closes #0 --> Related independent native-work reductions: #10127, #10128, npm/hosted-git-info#347, #10130. The independent empty-leaf refresh optimization is proposed in #10131. Its savings overlap this fast path; that PR includes a separate incremental comparison with this optimization already applied. Neither PR depends on the other. Co-authored-by: Copilot App <[email protected]>
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.
Cache unsuccessful hosted Git URL parses without changing their public
undefinedreturn.fromUrl()already tries to cache failures, but storesundefined, whichlru-cachedoes not retain. Consequently, repeated non-Git inputs repeat parsing. This matters to npm becausenpm-package-argtries hosted-Git classification while handling ordinary registry version specifications.Change and compatibility
nullas an internal failure sentinel; translate it back toundefinedon return.addHost()changes parser configuration, so an earlier failure does not hide a newly registered host.nullwording to describe the existing publicundefinedreturn, not a new API behavior.Measured effect
With only this fix applied to npm 11.17.0's hosted-git-info 9.0.3, using Node 24.22.0, Arborist 9.8.0, and lru-cache 11.5.1:
These are Dependabot-shaped
npm install <target> --package-lock-only --ignore-scriptscalls: the writer adds--force; the checker adds--dry-run=true. Both use--offline --audit=false --fund=false --timing.The measurements use an isolated large workspace workload, warm npm caches, networking disabled, one excluded warmup per arm, and three measured pairs with alternating order. No instrumentation was included in timing samples. All 4,686 manifest/lockfile outputs plus
.npmrcwere byte-identical across all eight runs per command shape; npm output also matched after removing timing text.A tiny project with one local dependency was effectively neutral over seven measured pairs: CPU 0.347578 -> 0.347536 s; wall 0.274601 -> 0.274895 s.
These are local native-command results, not complete Dependabot-job savings or a general performance guarantee. The large workload is not a public fixture. Negative entries also compete with successful results for the existing cache capacity.
Public reproduction of the avoided work
From a hosted-git-info checkout with dependencies installed:
Verified on upstream
mainand this branch: 20,000 -> 100 parser executions, with all calls still returningundefined. This counts work, rather than claiming a synthetic timing improvement.Validation
Source validation is against hosted-git-info 10.1.1, based on
mainat8c3bebb5e42142b7bce06b085b4c1bd1adba7371, using the repository's own development dependencies, lru-cache 11.5.3, and Node 24.22.0:npm run test:cover— passed, 31 tests, 100% lines/functions/branches.npm run eslint— passed across the repository.npm test— all 31 tests and ESLint pass, but the subsequenttemplate-oss-checkhook fails on existing generated configuration drift. A clean checkout of the same upstream commit, using identical dependencies, has the same five template-file differences. No tooling/configuration changes are included here.References
Related to #343. This fix is independent of replacing the cache implementation; that proposal currently also discards
undefinedvalues and should preserve negative caching and host-registration invalidation if it moves forward.