perf: Skip request-body compression for already-compressed content types - #987
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #987 +/- ##
==========================================
+ Coverage 94.65% 94.70% +0.04%
==========================================
Files 58 58
Lines 5259 5323 +64
==========================================
+ Hits 4978 5041 +63
- Misses 281 282 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Mantisus
approved these changes
Aug 3, 2026
Mantisus
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Only a small suggestion.
…on-for-compressed-types # Conflicts: # tests/unit/test_utils.py
B4nan
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_prepare_request_callnow checks the request'sContent-Typebefore compressing the body and skips compression for media types that already carry their own compression:image/*,audio/*, orvideo/*type,application/zip,application/gzip,application/x-7z-compressed, rar, bzip2, xz, zstd, jar),font/woff,font/woff2).Types with a
+json/+xmlstructured suffix stay compressible, soimage/svg+xmlis not caught by theimage/prefix. The media type is normalized before matching (parameters stripped, lowercased, trimmed). When compression is skipped, any caller-suppliedContent-Encodingheader 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_recordwith a 200 MB incompressible payload:application/octet-stream(unchanged)image/png(new path)application/octet-streamis 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 nocontent_typeis 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
bytesbody to impit'scontent=, 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