Repository navigation
Conversation
|
Looks good to me.
I think it would be interesting to get performance information when the connection goes over the internet. Compression would be more benificial on slow links, but I guess it would not make much of a difference as long as the query fits in one packet. |
|
I am in favor of this change and it makes sense to me. But I would like to see some justification for 512. Why is it 512 and not 50? Or maybe something in the middle? How much compression can we get by compressing a 512-byte-long string? Why is it even a power of 2? I would rather keep it at 50, just like libmysqlclient does or at most increase it to 100 bytes. Regarding the new test: it just looks like AI slop. I don't understand what exactly it tests or its relation to the change in this PR. It doesn't seem to verify that compression is happening. I think you should write the test yourself, or, if there is one, adjust an existing test to cover the branch change. |
|
There is no good reason for 512, and it being a power of 2 means nothing. I measured it on single statements of the kinds PHP applications send. I used 200 of each with random values and compressed them with
|
Yes, Claude gave me an almost identical table. From it, I read that 100 is the most that we can apply because after 100 bytes we already start to see some significant compression. Claude does not seem to understand that we are not trying to optimise the performance of the local CPU but the network instead. I think that keeping it at 50 bytes is the safest option. |
With
MYSQLI_CLIENT_COMPRESS, mysqlnd runscompress()on every packet it sends, however small. Each call sets up a new deflate stream, and short packets do not shrink, so the client pays the full setup cost for nothing.This sends packets smaller than 170 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.
compress()at level 6 on single statements of the kinds PHP applications send, 200 of each with random values, packet header included, zlib 1.3, one core:compress()COMMIT,SET NAMES utf8mb4COM_STMT_EXECUTEwith 1 parameterSELECT * FROM users WHERE id = ...wp_optionsautoloadCOM_STMT_EXECUTEwith 11 parametersUPDATEof 4 columns by idselect ... order by ... limitINSERTof one row with 11 columnsWP_QueryNothing under 50 bytes shrinks. From about 170 bytes typical queries save 20% or more, which is where the cost starts to pay off.
The test uses the fake server to read what the client sends and checks the uncompressed length in the compressed header: 0 for a 94 byte query and the real length for a 1014 byte one. Without the change the 94 byte query is sent compressed and the test fails.