{{ message }}
Repository navigation
fix: cache unsuccessful hosted Git URL parses - #347
Open
jeffwidman wants to merge 1 commit into
Open
jeffwidman wants to merge 1 commit into
jeffwidman wants to merge 1 commit into
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 <223556219+Copilot@users.noreply.github.com>
jeffwidman
commented
Oct 15, 2026
Member
Author
There was a problem hiding this comment.
Clarification: this corrects the documentation, not the public return type. Before this PR, an unrecognized URL already returned undefined; the existing upstream tests explicitly assert that.
The new null value is only an internal cache sentinel. It is translated back to undefined on return, so callers observe undefined both before and after this change. No public return-value change from null to undefined is introduced.
jeffwidman
marked this pull request as ready for review
October 15, 2026 06:18
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.