bzip3 and Beyond
Introduction
- The Economics of Compression
- The Compression Landscape
- Why bzip3 Matters
- What This Book Is Not
- How to Use This Book
Chapter 1: Information Theory Foundations
- Entropy and Its Meaning
- Shannon’s Source Coding Theorem
- Measuring Compression: Ratio, Bits-per-Byte, and Entropy Gap
- The Gap Between Theory and Practice
- Practical Implications for Compressor Design
Chapter 2: Symbol Coding: Huffman and Beyond
- Prefix Codes and the Kraft-McMillan Theorem
- Building a Huffman Tree
- Canonical Huffman Codes
- Arithmetic Coding: The Idea
- Range Coding: Why It Is Better Than Arithmetic Coding
Chapter 3: Dictionary Methods and LZ Algorithms
- LZ77: Sliding Window and Match Vectors
- LZ78 and the LZ Family Tree
- Deflate’s Approach to Dictionary Compression
- Match Finding: Hash Chains vs Binary Search vs FM-Index
- The Cost of Match Finding
Chapter 4: Block Transformations: BWT and MTF
- Why Transform Before Compressing
- The Burrows-Wheeler Transform Explained
- Inverting the BWT: The LF-Mapping Property
- Move-to-Front Coding
- How BWT+MTF Creates Compressible Distributions
Chapter 5: The bzip2 Architecture
- Block Size as a Design Parameter
- Sorting Runs: The In-place Suffix Sort
- Run-Length Encoding Before BWT
- Huffman Coding with Multiple Passes
- Where bzip2 Falls Short
Chapter 6: Block-Based Design Principles
- Why Blocks at All
- Block Size vs Compression Ratio vs Memory
- Independence and Parallelism
- Streaming with Blocks
- Error Localization and Recovery
- Summary: The Block Philosophy
Chapter 7: Range Coding Implementation
- The 64-bit Range Coder
- Handling Underflow and Renormalization
- Byte Output Buffering
- The Decoder Mirror
- Testing Range Coder Correctness
- Optimization Notes
Chapter 8: Context Modeling
- Order-0 vs Order-N Models
- Context Mixing and Blending
- Adaptive Probability Updates
- State Machines in Context Modeling
- Context Modeling for BWT Output
- The Cost of Context Modeling
Chapter 9: bzip3 Design Philosophy
- Motivations Behind bzip3
- The Modular Pipeline Approach
- LZH vs BWT Modes
- Choosing Between Pretransformation Strategies
- The Role of Preprocessing
Chapter 10: The bzip3 Compression Pipeline
- Chunking and Block Partitioning
- Pretransformation and Dictionary Compression
- Transform Selection and Encoding
- Context Modeling the Transformed Stream
- Range Encoding to Final Bits
- Why This Pipeline Works
Chapter 11: Implementing a Reference bzip3-style Compressor
- Project Layout and Build System
- The Block Structure and API
- BWT Implementation in C
- MTF and Context Modeling Code
- Putting It All Together
Chapter 12: SIMD and Vectorization
- Where SIMD Helps in Compression
- Vectorizing Match Finding
- SIMD-Accelerated Sorting
- Vectorized Range Coding
- Portability and Auto-Vectorization
- Measuring SIMD Benefits
Chapter 13: Parallel Compression Architectures
- Parallel Patterns in Compression
- Block-Level Parallelism
- Shared Memory and Lock-Free Queues
- Producer-Consumer Pipeline Design
- Scaling Limits and Amdahl’s Law
Chapter 14: Streaming Compression Design
- Stream vs Block: Reconciling the Tension
- Chunk Boundaries and Backreferences
- Flushing and Partial Results
- Seeking and Indexing
- Handling Stream Corruption
- API Design for Streaming
Chapter 15: Memory Engineering
- Memory Footprint Analysis
- Cache Line Behavior and Data Layout
- Arena Allocators and Pooling
- Reducing Allocation in Hot Paths
- Low-Memory Mode Trade-offs
- Memory and Parallelism
Chapter 16: I/O and System Integration
- The I/O Bottleneck
- Buffering Strategies
- Asynchronous I/O with Compression
- Pipe and Network Throughput
- Compression on the Fly vs Batch
Chapter 17: File Format Design
- Magic Numbers and Headers
- Metadata and Flags
- CRC and Integrity Checking
- Forward Compatibility
- bzip3 Format Decoded
Chapter 18: Benchmarking and Profiling
- Compression Benchmarks: Tools and Standards
- Designing Fair Comparisons
- Measuring Throughput and Latency
- Profiling with perf and Valgrind
- Interpreting Benchmark Results
Chapter 19: The Broader Landscape
- LZ4 and the Speed Extreme
- Zstandard: Adaptive Compression
- Brotli: Static Dictionary Power
- xz/LZMA: Ratio Focused
- When to Use Which Compressor
Chapter 20: Security and Correctness
- Decompression Bombs and Limits
- Bounds Checking Everywhere
- Integer Overflow and Wraparound
- Fuzz Testing Compression Code
- Side Channels in Compression
- CVEs and Real-World Vulnerabilities
Chapter 21: API Design and Library Engineering
- Stream vs Batch APIs
- Error Handling Semantics
- Thread Safety and Initialization
- ABI Stability
- Example API Design
Chapter 22: Production Deployment
- Compression on Servers and Storage
- Network Compression Trade-offs
- Choosing Levels and Parameters
- Monitoring and Alerting
- Migration Strategies
Chapter 23: Beyond bzip3
- Neural and Learned Compression
- Compression for Non-Text Workloads
- Hardware Acceleration
- The End of the Compression Line
- Open Problems