perf(compression): send no Vary on a body under the threshold
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>
This commit is contained in:
4 files changed
+18
-9
No files matched your search
+4
-1
@@ -163,7 +163,10 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
preference. Text, JSON, JavaScript, ndjson, SVG, XML and wasm are compressed. A response that
|
||||
already has `Content-Encoding` or `Content-Range`, has no `Content-Type`, or says
|
||||
`Cache-Control: no-transform` is left alone. `Vary: Accept-Encoding` is added wherever the request
|
||||
decided the outcome: identity clients, `HEAD`, bodies under the threshold and every `304`.
|
||||
decided the outcome: identity clients, `HEAD` and every `304`. A body under the threshold gets
|
||||
none: it is sent identity whatever the client accepts, and Deno pays about 10% of a small request
|
||||
for the header (about 3% on Bun). On the edge, where Cloudflare encodes, every compressible
|
||||
response keeps `Vary`.
|
||||
`Content-Length` is dropped from an encoded body. SSE and ndjson streams are compressed too,
|
||||
flushed after every event, error frame and ping, so each event decodes when it arrives.
|
||||
Per runtime:
|
||||
|
||||
Reference in new issue
Block a user