-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Optimize recvAndDecompress when receiving compressed payload #7786
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
Conversation
b115b69
to
ee988fd
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7786 +/- ##
==========================================
+ Coverage 81.39% 81.42% +0.03%
==========================================
Files 368 368
Lines 36799 36814 +15
==========================================
+ Hits 29952 29977 +25
+ Misses 5615 5606 -9
+ Partials 1232 1231 -1
|
@PapaCharlie @dfawley When you get a chance, can you take a peek on this? Maybe indeed it does not make sense to call |
ee988fd
to
5e127c4
Compare
…g compression Signed-off-by: alanprot <alanprot@gmail.com>
5e127c4
to
8a8fe07
Compare
We have another ongoing PR which addresses this issue. Please see: #7653 |
@alanprot Can you try replacing the
I would have expected to see no difference between old and new |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
@PapaCharlie @easwars yeah.. i think we can close this one in favor of that one. IDK if we wanna use the benchmark tests from here though.
|
Thanks @alanprot |
@alanprot just to be clear, are those benchmark results just with |
Nevermind, you can't really use both |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Is there a date for the release of 1.69? |
12/10/2024 is the scheduled date. Give it +/- 3 days. |
Awesome! Thank you!! :D |
The PR #7356 in grpc-go introduced a new Codec that uses mem.BufferSlice instead of []byte and also began pooling the underlying []byte slices by default.
With this update, the DecompressedSize method is no longer called for codecs that implement it. Previously, this method was used to determine the size of compressed content, allowing us to allocate the destination []byte with the correct size to avoid oversized slices or reallocation. The reasoning behind the change is that, since the slices are now pooled, the "decompress" method would use multiple smaller slices rather than a single large one, thereby reducing overhead due overallocation/reallocation. See this comment.
The problem is that the method io.Copy allocates a temporary32kb byte slice internally on each call: See
https://github.com/golang/go/blob/889abb17e125bb0f5d8de61bb80ef15fbe2a130d/src/io/io.go#L387-L389
And
https://github.com/golang/go/blob/889abb17e125bb0f5d8de61bb80ef15fbe2a130d/src/io/io.go#L417-L427
This PR now uses uses the io.CopyBuffer method instead of io.Copy, allowing us to pass a []byte used internally directly as a parameter. This buffer now is also being pulled using the new
mem
package. This change also reintroduces the call to the DecompressedSize method when available or assume the same 32kb to request the the buffer from the pool.From the doc
I create a benchmark with zip (which implements the
DecompressedSize
method) and anoop
compression that does not implement theDecompressedSize
method.