-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compression is applied to empty messages, which makes them bigger, not smaller #6831
Comments
Fixes grpc#6831. gzip compressing messages less than 21 bytes is always unfruitful, it always results in "compressed" messages that are longer than the original message length, since the minimum length of a gzipped message is 21 bytes, due to headers and CRC trailer.
Can you explain the significance of this issue for you? Whether you do some epsilon additional work to produce a small amount more data, empty messages would still be extremely small and fast to transmit. This feels like a micro-optimization to me. Note that a custom compressor could also implement similar behavior internally. |
If this optimisation took 1000 lines of code to implement, then I would agree, it's a micro-optimisation that isn't worth the code to implement it. But that's not what this is. It's a 2 line branch that reduces the size of empty frames by over 80%. The Java implementation doesn't compress empty messages, this behaviour isn't without precedent. If you'd like it to be simpler, I could change it to match the behaviour of the Java implementation and not decompress empty messages, rather than having a length limit of 21. |
Even optimizing empty messages by 100% seems unlikely to have any measurable impact in any real system.
I think if we do this, I'd prefer to have an optional magic error ( |
That sounds reasonable to me. I'm happy to implement that if you're willing to accept it. |
SGTM, thanks! |
One thing that just occurs to me, is possibly returning |
I would say "no", since the dependency we care about is gRPC consuming this and users implementing it, not the other way around. But calling it out in the release notes SGTM. |
Sounds fine to me. |
There's a problem with this approach. The So, I don't think this can be implemented inside the |
Yeah..I think you could take advantage of the fact that we know I'm fine with the 0-size skipping in that case. Or if you wanted to optimize even further, add a second optional method to |
Fixes grpc#6831. This avoids compressing messages that are empty, since you can't compress zero bytes to anything smaller than zero bytes, and most compression algorithms output headers and trailers which means the resulting message will be non-zero bytes.
Fixes grpc#6831. This avoids compressing messages that are empty, since you can't compress zero bytes to anything smaller than zero bytes, and most compression algorithms output headers and trailers which means the resulting message will be non-zero bytes.
Fixes #6831. This avoids compressing messages that are empty, since you can't compress zero bytes to anything smaller than zero bytes, and most compression algorithms output headers and trailers which means the resulting message will be non-zero bytes.
From my reading of the source code, it appears that compression is applied to empty messages. This makes no sense, an empty message is 0 bytes long, while a gzipped compressed empty message is at least 21 bytes long. Empty messages should never be compressed. It makes no sense to compress any message that is less than 21 bytes, since the compressed message will always end up being longer than the original.
Example of where compression is done without checking the message length first:
https://github.com/grpc/grpc-go/blob/1b05500d8019885575a37efa2e961e278d680ee9/server.go#L1138C19-L1138C28
The text was updated successfully, but these errors were encountered: