Update upperBound ratio when guessing the required decompression buffer size #141
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We noticed that for one of our services we sometimes have a lot of allocations caused by the
ioutil.ReadAll
call in theDecompress
method.After investigation those are coming from buffers whose decompressed size is greater than 10x the input size. This is quite wasteful because it means that we allocate twice for those buffers.
Once in this branch:
zstd/zstd.go
Line 143 in 869dae0
And another time here once we realise that the buffer we previously allocated wasn't big enough:
zstd/zstd.go
Line 154 in 869dae0
We have this limit to avoid malicious payloads but we noticed that this actually triggered quite often for one of our services whose compression rates are above 10x.
This technically doesn't fully solve the problem but it should now happen less often. I can also make this upper bound configurable if this change sounds too scary