Why a Compressor Can Produce a Larger File

A format needs storage for its decoding information, and many inputs have few patterns the codec can exploit.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a short record
  2. Check the intended corpus
  3. Count a short payload and its surrounding bytes
  4. Choose fallback behavior using the whole object contract

Trace a short record

A five-byte source may turn into a four-byte encoded payload plus a two-byte header, making six bytes total. Compressed size and headers give the comparison.

Check the intended corpus

Measure repeat patterns and several sizes so one favorable repeated string does not overstate the result. Representative workloads supply a way to choose the sample.[1][2]

Count a short payload and its surrounding bytes

A four-byte raw record might compress to two payload bytes. Adding a format header of five bytes produces seven total. Compression reduced the payload but expanded the object the consumer stores. See size with a header.

Raw representation: 4 bytes
Compressed payload: 2 bytes
Header: 5 bytes
Final representation: 7 bytes

Choose fallback behavior using the whole object contract

A format can permit writing raw data with an explicit marker when compression is unhelpful. Test an empty input, a short repeated message and already compact data.

References

  1. Claude E. Shannon, A Mathematical Theory of Communication ↩
  2. David J. C. MacKay, Information Theory, Inference, and Learning Algorithms ↩