perf(compression): stop charging uncompressed responses for compression being on #179

Merged
chrnx merged 2 commits from perf/compression-skip-buffer into develop 2026-10-29 14:47:38 +00:00
2 Commits
Author SHA1 Message Date
chrnx fe4827ccb3 perf(compression): send no Vary on a body under the threshold
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 22s
CI / runtimes (deno) (pull_request) Successful in 33s
A buffered body under the threshold is sent identity whatever the client
accepts, so Accept-Encoding played no part in it and RFC 9110 asks for
no Vary. A cache that stores it for everyone is right to: every client
accepts identity. Responses that are encoded, or that are identity for
a request-side reason (identity client, HEAD), and every 304 keep Vary,
as does every compressible edge response, since Cloudflare encodes
there.

Deno pays about 10% of a small request for the header, Bun about 3%.
The size is also measured with Buffer.byteLength instead of allocating
the bytes, which are now built only when the body is encoded.

Measured on the Mac, hello with compression on against compression off:
Deno -17% -> -2%, Bun -7% -> -3%.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-28 22:39:06 -05:00
chrnx e8842e6e06 perf(compression): decide eligibility in one pass over the headers
eligible() read four headers through findHeader, each an Object.keys and
a toLowerCase per key, then ran two regexes, on every response while
compression is on. It now walks the keys once, keeps the first value of
each name as findHeader did, memoizes the content-type decision for the
last type seen, and tests no-transform only when cache-control is set.

Measured on Deno, hello with compression on (under the threshold): +2-5%.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-28 22:33:54 -05:00