Why doesn't lz4 keep small/uncompressible values uncompressed?

247 Views Asked by At

When compressing small values (< 500 bytes or so), and for uncompressible random values, lz4 returns data that is much larger than the original value (e.g. 27 bytes from 4).

When a large amount of such values is compressed separately (e.g. in a key-value storage), this adds up.

Question is: why doesn't lz4 use e.g. a separate magic number for values that didn't become smaller after compression, leaving the original data as-is, and only adding 4 bytes of the overhead?

The same applies to many other compression formats.

Code with demonstration: https://jsfiddle.net/gczy7f3k/2/

1

There are 1 best solutions below

0
On

I believe this is something you have to decide on higher level.

You can determine yourself if you want to compress, and add a marker (magic numbers) if the data is compressed.