Skip to content

Question: snappy compression on large data is not compressed, and message size enlarged by 7 bytes. #856

Answered by klauspost
3AceShowHand asked this question in Q&A
Discussion options

You must be logged in to vote

Let's go through my answer. dstLimit := len(src) - len(src)>>5 - 5 describes the maximum output size before we reject the compression.

If you are unfamiliar with bit shifting, it can also be written as: dstLimit := len(src) - (len(src)/32) - 5.

This means that the limit is "the size if the input" minus "the size divided by 32", minus 5.

Take an input of 1000 bytes. We then replace and it becomes dstLimit = 1000 - (1000/32 = 31) - 5 = 964. If we get to or exceed this limit, we emit the block as uncompressed.

For best, the limit is 1000-5 = 995 bytes.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@klauspost
Comment options

Comment options

You must be logged in to vote
1 reply
@klauspost
Comment options

Answer selected by 3AceShowHand
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #855 on August 25, 2023 09:43.