Codecs Overview
compressionz supports seven compression codecs, each with different characteristics. This page provides a high-level overview.
Codec Summary
Section titled “Codec Summary”| Codec | Type | Speed | Ratio | Best For |
|---|---|---|---|---|
| Zstd | Dictionary | Very Fast | Excellent | General purpose |
| LZ4 | LZ77 | Fastest | Good | Speed-critical |
| Snappy | LZ77 | Very Fast | Moderate | Real-time |
| Gzip | Deflate | Moderate | Good | Compatibility |
| Brotli | Dictionary | Slow | Best | Web assets |
| Zlib | Deflate | Moderate | Good | PNG, legacy |
Compression Algorithm Families
Section titled “Compression Algorithm Families”LZ77-Based
Section titled “LZ77-Based”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
Deflate-Based
Section titled “Deflate-Based”How it works: LZ77 + Huffman coding for better ratios.
Codecs: Gzip, Zlib, Deflate
Characteristics:
- Good compression ratios
- Moderate speed
- Universal compatibility
- Established standard
Dictionary-Based
Section titled “Dictionary-Based”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
Performance Comparison
Section titled “Performance Comparison”Throughput (1 MB Data)
Section titled “Throughput (1 MB Data)”Compression Speed (GB/s)┌──────────────────────────────────────────────────────┐│ LZ4 Raw ████████████████████████████████████ 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 Raw ████████ 8.1 ││ LZ4 Frame ████ 3.8 ││ Gzip ██ 2.4 ││ Brotli ██ 1.9 │└──────────────────────────────────────────────────────┘Compression Ratio
Section titled “Compression Ratio”On mixed-pattern 1 MB data:
| Codec | Compressed Size | Ratio |
|---|---|---|
| Brotli (best) | 535 bytes | 99.9% |
| Zstd | 684 bytes | 99.9% |
| Gzip | 4,382 bytes | 99.6% |
| LZ4 Raw | 4,541 bytes | 99.5% |
| LZ4 Frame | 7,057 bytes | 99.3% |
| Snappy | 47,468 bytes | 95.3% |
Feature Matrix
Section titled “Feature Matrix”| Feature | Zstd | LZ4 | LZ4 Raw | Snappy | Gzip | Brotli | Zlib |
|---|---|---|---|---|---|---|---|
| Streaming | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ |
| Dictionary | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Checksum | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ |
| Auto-detect | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ |
| Zero-copy | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Pure Zig | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
Implementation Details
Section titled “Implementation Details”| Codec | Source | Version | License |
|---|---|---|---|
| Zstd | Vendored C | 1.5.7 | BSD |
| Gzip/Zlib | Vendored C (zlib) | 1.3.1 | zlib |
| Brotli | Vendored C | Latest | MIT |
| LZ4 | Pure Zig | - | Apache 2.0 |
| Snappy | Pure Zig | - | Apache 2.0 |
Choosing a Codec
Section titled “Choosing a Codec”Quick Decision
Section titled “Quick Decision”- Default choice: Zstd
- Maximum speed: LZ4 Raw
- Web compatibility: Gzip or Brotli
- Real-time messaging: Snappy
Decision Tree
Section titled “Decision Tree”┌─ Need maximum speed?│ ├─ Yes → LZ4 Raw (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.
Codec Deep Dives
Section titled “Codec Deep Dives”Learn more about each codec:
- Zstandard (Zstd) — Best overall balance
- LZ4 — Maximum speed
- Snappy — Real-time applications
- Gzip — Universal compatibility
- Brotli — Maximum compression
- Zlib & Deflate — Legacy formats