Reduce npm package and version lookup allocations - #87
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes preserve existing behavior with regression coverage and benchmarks.
Pull request overview
Optimizes npm package and version lookups by decoding only the selected release while preserving fallback behavior.
Changes:
- Added targeted release decoding and optional
FetchVersionsupport. - Preserved metadata, errors, cancellation, and registry fallbacks.
- Added regression tests and allocation benchmarks.
File summaries
| File | Description |
|---|---|
npm_lookup_test.go |
Tests lookup behavior, errors, metadata, and fallbacks. |
npm_bench_test.go |
Benchmarks allocations and concurrent lookups. |
internal/npm/npm.go |
Implements selective release decoding. |
internal/core/helpers.go |
Dispatches optional direct version lookups. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
andrew
force-pushed
the
bench/npm-enrichment
branch
from
September 14, 2026 12:09
901bb0d to
2d60c6f
Compare
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.
Npm package and single-version lookups currently decode every release in the package document, and
FetchVersionFromPURLalso builds metadata for every release before selecting one. Decode only the selected release and use an optionalFetchVersionmethod, retaining the list fallback for other registries and npm publication times and provenance metadata.The new public-API benchmarks measure separate and concurrent lookups with 1–2,000 releases. For a concurrent pair with 500 releases, allocated bytes fall by 45% and allocation count by 94%; at 2,000 releases, the reductions are 47% and 95%. One-release responses allocate about 0.5–0.6 KB more per lookup, with no significant timing change in the repeated comparison. Request counts and downloaded bytes are unchanged.
Selected lookups still reject malformed JSON and invalid fields in the selected release, but no longer validate field types inside unrelated releases. Regression coverage includes metadata equality with the full list, scoped names, package fallbacks, missing releases, errors, cancellation, and the other-registry fallback.