Skip to content

perf(registry): memoize component-info discoverability probe per baseUrl - #1566

Open
ricardo-devis-agullo wants to merge 2 commits into
masterfrom
perf/registry-component-info-memoize
Open

perf(registry): memoize component-info discoverability probe per baseUrl#1566
ricardo-devis-agullo wants to merge 2 commits into
masterfrom
perf/registry-component-info-memoize

Conversation

@ricardo-devis-agullo

Copy link
Copy Markdown
Collaborator

Problem: packages/oc/src/registry/routes/component-info.ts:74 called isUrlDiscoverable(href) (undici GET to the registry's own baseUrl) on EVERY HTML info-page request, adding a full HTTP round trip to each ~info view even though the result only changes when deployment config changes.

Fix:

  • packages/oc/src/registry/routes/helpers/is-url-discoverable.ts: memoize the probe promise per baseUrl in a module-level Map for process lifetime, with in-flight dedup (concurrent requests share one probe). Probe logic itself unchanged.
  • packages/oc/src/registry/routes/component-info.ts: no logic change; documents that the self-probe is now cached. Fallback to //host+prefix on not-discoverable preserved.

Invalidation / escape hatch:

  • Exported clearDiscoverabilityCache(url?) clears one entry or the whole cache (for tests/ops).
  • OC_DISCOVERABILITY_NO_CACHE=1/true bypasses the cache and forces a fresh probe every call.

Verify:

  • Extended test/unit/registry-routes-helpers-is-url-discoverable.js: same baseUrl issues ONE probe, concurrent in-flight calls dedupe to one request, different baseUrl probes again, clear(url)/clear() force re-probe, env flag forces re-probe.
  • New test/unit/registry-routes-component-info-discoverability.js: repeated HTML info renders with same baseUrl issue ONE undici probe; different baseUrl probes again; re-probes after clear; //host+prefix fallback kept when not discoverable.
  • Results: 16/16 targeted tests pass; full registry-routes suite 198/198 pass. tsc (TS 6.0.3) and biome check clean on touched src files.

component-info HTML route self-probed the registry over HTTP
(isUrlDiscoverable GET to own baseUrl) on every ~info request, even
though the result only changes when deployment config changes.

Cache the probe promise per baseUrl for process lifetime with in-flight
dedup; add clearDiscoverabilityCache() escape hatch for tests plus
OC_DISCOVERABILITY_NO_CACHE=1/true to force re-probing. Fallback to
//host+prefix on not-discoverable is unchanged.
Unbounded module-level Map keyed by baseUrl could grow forever when a
host-based baseUrlFunc yields distinct baseUrls per Host (perf item 7).
Use the registry's BoundedCache (LRU, max 100 entries) keyed by baseUrl
instead. Semantics unchanged: per-baseUrl memoization, in-flight promise
dedup, clearDiscoverabilityCache(url?)/clear-all, OC_DISCOVERABILITY_NO_CACHE
bypass, rejection eviction adapted to the BoundedCache API.
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