Skip to content

perf(registry): memoize semver version resolution - #1568

Open
ricardo-devis-agullo wants to merge 1 commit into
masterfrom
perf/registry-semver-resolution-cache
Open

perf(registry): memoize semver version resolution#1568
ricardo-devis-agullo wants to merge 1 commit into
masterfrom
perf/registry-semver-resolution-cache

Conversation

@ricardo-devis-agullo

Copy link
Copy Markdown
Collaborator

Problem: repository.getComponent (domain/repository.ts:305) calls versionHandler.getAvailableVersion on every render; unversioned requests re-run semver.maxSatisfying over all versions and ranged requests re-match everything.

Fix: memoize resolved versions in a module-level WeakMap keyed by the versions-array reference, each entry a Map<requestedVersion, resolvedVersion> (misses/undefined cached too). The registry replaces (never mutates) versions arrays on publish/poll refresh, so the array reference is the invalidation token: new snapshots re-resolve, stale entries are GC'd with the old array, no manual invalidation. Falsy requests (undefined, '') share one entry since they take the same branch. Fail-open: non-array versions input bypasses the cache and delegates to the real resolver; cache read/write is guarded so it can never break resolution. Touches only domain/version-handler.ts (repository.ts needs no change; routes/index.ts, middleware/*, compression/adapter files untouched).

Verify: new spec test/unit/registry-domain-version-handler-cache.js covers range semantics (exact, range, unversioned-max, prerelease-only, mixed, unsatisfiable), proves via sinon callThrough stubs that semver.maxSatisfying is called once per (array, requested) pair (incl. negative caching) and re-resolves on a new array reference, and checks fail-open (frozen arrays, nullish requests, exotic versions input). Full packages/oc suite (test-silent): 1110 passing, 0 failing.

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