Skip to content

Codecs Overview

compressionz supports seven compression codecs, each with different characteristics. This page provides a high-level overview.

CodecTypeSpeedRatioBest For
ZstdDictionaryVery FastExcellentGeneral purpose
LZ4LZ77FastestGoodSpeed-critical
SnappyLZ77Very FastModerateReal-time
GzipDeflateModerateGoodCompatibility
BrotliDictionarySlowBestWeb assets
ZlibDeflateModerateGoodPNG, legacy

How it works: Find repeated sequences, replace with (offset, length) pairs.

Codecs: LZ4, Snappy

Characteristics:

  • Very fast compression and decompression
  • Moderate compression ratios
  • Simple implementation
  • Low memory usage

How it works: LZ77 + Huffman coding for better ratios.

Codecs: Gzip, Zlib, Deflate

Characteristics:

  • Good compression ratios
  • Moderate speed
  • Universal compatibility
  • Established standard

How it works: Pre-computed probability tables and advanced entropy coding.

Codecs: Zstd, Brotli

Characteristics:

  • Excellent compression ratios
  • Asymmetric (compression slower than decompression)
  • Higher memory usage
  • Modern algorithms
Compression Speed (GB/s)
+------------------------------------------------------+
| LZ4 Block #################################### 36.6 |
| Snappy ############################### 31.6 |
| Zstd ############ 12.0 |
| LZ4 Frame ##### 4.8 |
| Gzip ## 2.4 |
| Brotli # 1.3 |
+------------------------------------------------------+
Decompression Speed (GB/s)
+------------------------------------------------------+
| Zstd ############ 11.6 |
| Snappy ######### 9.2 |
| LZ4 Block ######## 8.1 |
| LZ4 Frame #### 3.8 |
| Gzip ## 2.4 |
| Brotli ## 1.9 |
+------------------------------------------------------+

On mixed-pattern 1 MB data:

CodecCompressed SizeRatio
Brotli (best)535 bytes99.9%
Zstd684 bytes99.9%
Gzip4,382 bytes99.6%
LZ4 Block4,541 bytes99.5%
LZ4 Frame7,057 bytes99.3%
Snappy47,468 bytes95.3%
FeatureZstdLZ4 FrameLZ4 BlockSnappyGzipBrotliZlib
StreamingYesYesNoNoYesYesYes
DictionaryYesNoNoNoNoNoYes
ChecksumYesYesNoNoYesNoYes
Auto-detectYesYesNoYesYesNoYes
Zero-copyNoYesYesYesNoNoNo
Pure ZigNoYesYesYesNoNoNo
CodecSourceVersionLicense
ZstdVendored C1.5.7BSD
Gzip/ZlibVendored C (zlib)1.3.1zlib
BrotliVendored CLatestMIT
LZ4Pure Zig-Apache 2.0
SnappyPure Zig-Apache 2.0
  • Default choice: Zstd
  • Maximum speed: LZ4 Block
  • Web compatibility: Gzip or Brotli
  • Real-time messaging: Snappy
+- Need maximum speed?
| +- Yes -> LZ4 Block (if you track size) or Snappy
| +- No -+
| |
+- Need web compatibility?
| +- Static assets -> Brotli
| +- Dynamic content -> Gzip
| +- No -+
| |
+- Need streaming?
| +- Fast + checksum -> LZ4 Frame
| +- Best ratio -> Zstd
| +- No -+
| |
+- Default -> Zstd (best overall)

See Choosing a Codec for detailed guidance.

Learn more about each codec: