[php-src] PR #24702: mysqlnd: Do not compress packets smaller than 512 bytes
| From: | lohmag | Date: | Sun, 25 Oct 2026 21:18:11 +0000 |
| Subject: | [php-src] PR #24702: mysqlnd: Do not compress packets smaller than 512 bytes | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39877@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24702
Author: lohmag
With
MYSQLI_CLIENT_COMPRESS, mysqlnd runs compress() on every packet it
sends, however small. Each call sets up a new deflate stream, and below a few hundred bytes the
packet barely shrinks, so the client pays the full setup cost for almost nothing.
This sends packets smaller than 512 bytes uncompressed inside the compressed envelope (uncompressed
length 0), which the protocol already allows and which mysqlnd already does for packets that do not
shrink. libmysqlclient uses the same mechanism with a 50 byte threshold.
Client CPU per query, release build, one pinned core, MySQL 8.0.46 on the same host, SELECT
'<n bytes>' over a compressed connection, median of 5 runs of 50000 queries:
| Query size | Before | After |
|---|---|---|
| 100 B | 7.72 µs | 4.76 µs |
| 300 B | 8.20 µs | 4.86 µs |
| 600 B | 8.97 µs | 8.96 µs |
| 2000 B | 11.31 µs | 11.39 µs |
The new test sends payloads on both sides of the threshold, including random data that does not
compress, and checks that each one comes back intact.