Repository navigation
Compress only packets of 512 bytes or more - #1834
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Threshold behavior compress.go, compress_test.go |
The minimum length for attempting compression increases to 512 bytes. A new test checks packets one byte below and exactly at the threshold. Existing fallback behavior remains unchanged. |
Contributor list
| Layer / File(s) | Summary |
|---|---|
Contributor listing AUTHORS |
Nikita Massalitin is added to the individual contributors list. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Other
Possibly related PRs
- go-sql-driver/mysql#1833: Both changes raise
minCompressLengthfrom 150 to 512 incompress.go.
Suggested reviewers: joe-mann
Merge Risk: 
Minimal · up to 2caac
-
No actionable merge-blocking risk remains in the reviewed changes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Description
The threshold change from #1833, without the klauspost dependency: packets shorter than 512 bytes are sent uncompressed (was 150). It only affects what the driver sends (queries, statement parameters,
LOAD DATA), since results are compressed by the server.The threshold mainly helps Go 1.25 and 1.26. There
compress/zlibat level 2 costs at least about 5.6 µs per packet, even for one byte, because the compressor clears its hash tables on the first write afterReset, so every packet of 150 to 511 bytes costs 10 to 14 µs, and one of up to 256 bytes saves at most 68 bytes for it. Go 1.27 rewrotecompress/flate(golang/go#75532): the fixed cost is gone, short packets that do not shrink are stored for about 0.2 µs (and the driver then sends them uncompressed), and the rest compresses 2 to 3 times faster. On Go 1.27 the change gives up some savings instead: SQL text below about 350 bytes is stored anyway, but from 384 to 511 bytes it shrinks by about a quarter for 5 to 6 µs, and JSON-like data shrinks well from 150 bytes up (a 384 byte packet to 53% for 4.8 µs).Per packet,
compress/zliblevel 2 through a reused writer as inzCompress, AMD Ryzen 9 7950X3D, one pinned core. Compressed size is the zlib output relative to the input, above 100% means the driver sends the packet uncompressed.SQL text (
SELECT ... WHERE uuid = '...',UPDATE ..., multi-rowINSERT ... VALUES):JSON-like parameter data:
go.modstill allows Go 1.25, so most users ofcompress=truetoday pay the Go 1.25 and 1.26 cost. If you would rather tune for Go 1.27, a lower value such as 384 keeps the JSON savings there and still drops the most expensive packets on older Go.Checklist
TestCompressThresholdpins the boundary instead: a packet one byte shorter thanminCompressLengthis sent uncompressed and one ofminCompressLengthbytes is compressed.go test -race ./..., and the full suite against MySQL 8.0.46 including everycompressvariant (581 passed,TestConcurrentskipped withoutMYSQL_TEST_CONCURRENT).