Skip to content

Reduce npm package and version lookup allocations - #87

Merged
andrew merged 1 commit into
mainfrom
bench/npm-enrichment
Sep 14, 2026
Merged

Reduce npm package and version lookup allocations#87
andrew merged 1 commit into
mainfrom
bench/npm-enrichment

Conversation

@andrew

@andrew andrew commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Npm package and single-version lookups currently decode every release in the package document, and FetchVersionFromPURL also builds metadata for every release before selecting one. Decode only the selected release and use an optional FetchVersion method, 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 FetchVersion support.
  • 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
andrew force-pushed the bench/npm-enrichment branch from 901bb0d to 2d60c6f Compare September 14, 2026 12:09
@andrew
andrew merged commit e4f8a48 into main Sep 14, 2026
5 checks passed
@andrew
andrew deleted the bench/npm-enrichment branch September 14, 2026 12:18
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.

2 participants