perf: Skip request-body compression for already-compressed content types (#987)
### What `_prepare_request_call` now checks the request's `Content-Type` before compressing the body and skips compression for media types that already carry their own compression: - any `image/*`, `audio/*`, or `video/*` type, - archives (`application/zip`, `application/gzip`, `application/x-7z-compressed`, rar, bzip2, xz, zstd, jar), - web fonts (`font/woff`, `font/woff2`). Types with a `+json`/`+xml` structured suffix stay compressible, so `image/svg+xml` is not caught by the `image/` prefix. The media type is normalized before matching (parameters stripped, lowercased, trimmed). When compression is skipped, any caller-supplied `Content-Encoding` header is dropped as well — the body goes out verbatim, so the header would otherwise misdescribe it. ### Why The client compressed every request body unconditionally. For already-compressed payloads that burns CPU and holds a second full copy of the body in memory, while typically producing output slightly *larger* than the input. Key-value store records — screenshots, video, archives — are exactly this case. End-to-end `set_record` with a 200 MB incompressible payload: | Content type | Peak RSS | Wall / CPU | |---|---|---| | `application/octet-stream` (unchanged) | 604 MB - 3.02x | 7.8 s / 6.9 s user | | `image/png` (new path) | 403 MB - 2.02x | 1.05 s / 0.40 s user | `application/octet-stream` is deliberately not on the list: it is the catch-all for unknown binary, which may well be uncompressed data. It is also the encoder's default when no `content_type` is passed, so the optimization only applies when the caller sets an accurate content type — documented in the compression concept page. The remaining 2x comes from handing a `bytes` body to impit's `content=`, tracked separately in #972. ### Notes This overlaps with #934 (skip compression for small payloads) — both add a condition to the same block in `_prepare_request_call`. Whichever lands second needs the two conditions combined. *✍️ Drafted by Claude Code*
V
Vlada Dusek committed
808bdde06ed1befe9d30bede0f947320240747a6
Parent: 7a5ed88
Committed by GitHub <noreply@github.com>
on 8/3/2026, 3:06:06 PM