Skip to content

perf(registry): use weak ETag in express adapter - #1565

Open
ricardo-devis-agullo wants to merge 2 commits into
masterfrom
perf/registry-weak-etag
Open

perf(registry): use weak ETag in express adapter#1565
ricardo-devis-agullo wants to merge 2 commits into
masterfrom
perf/registry-weak-etag

Conversation

@ricardo-devis-agullo

@ricardo-devis-agullo ricardo-devis-agullo commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Change: default the express adapter to weak ETag (the Express default).

Why: packages/oc/src/registry/domain/http-server/express-adapter.ts explicitly set app.set('etag', 'strong'). No consumer relies on strong semantics (verified below). Weak keeps conditional-request/304 support with the W/ prefix and weak comparison, and restores the Express default. No static-file handling touched (registry has no express.static usage; static assets are served elsewhere).

No CPU saving is claimed: the etag package SHA-1 hashes string/Buffer bodies in both weak and strong modes (verified against its source -- weak only adds the W/ prefix and relaxes comparison). Fully skipping ETag generation for JSON responses would be a separate behavior change and is out of scope for this PR.

Consumer check (no reliance on strong ETags):

  • grep If-None-Match/if-none-match across packages/: only oc-fastify-server-adapter tests send it.
  • grep ETag/etag in packages/oc/src: only the adapter setting, plus unrelated refreshInterval hits and a 304 passthrough in registry/routes/helpers/get-component-fallback.ts (forwards client headers to the fallback registry; clients don't send validators).
  • oc-client-browser sends no If-None-Match; batch POST (registry/routes/components.ts) and render routes return res.json with no conditional handling.

Fastify parity (not changed): packages/oc-fastify-server-adapter/src/index.ts:240 registers @fastify/etag with { weak: false, replyWith304: true } (strong), asserted in test/index.test.ts:43-72 and test/registry-node.ts:242-249. Left untouched to keep this PR minimal; a parity follow-up can flip weak:true plus those assertions if desired.

Verify headers:

  • dist adapter check: app.get('etag') === 'weak'; GET /component -> 200 ETag: W/"b-..." (W/ present); raw-http conditional GET with If-None-Match -> 304.
  • lock-in unit test in packages/oc/test/unit/registry-domain-http-server.js asserts adapter.native().get('etag') === 'weak'.
  • unit: npx mocha test/unit/registry-domain-http-server.js (packages/oc) -> 3 passing.
  • build: npm run build (turbo) -> 11 successful; biome check on touched files clean.

Bench: not run. bench:quick is 3 scenarios x 3 repetitions x 15s per branch (5+ minutes for both branches), and any RPS/p95 delta would be noise given both etag modes hash identically -- reporting numbers would be misleading.

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