Skip to main content
PPMd (Prediction by Partial Matching, variant D) is a compression method based on context modeling and statistical prediction. It provides excellent compression ratios for text and other highly structured data.

Method ID

ID: 03 04 01 (hex) The PPMd method is identified by the 3-byte sequence 03 04 01 in 7z archive format.

Overview

7-Zip includes two PPMd implementations:

PPMd Variant H (PPMd7)

Original PPMd algorithm from 2001
  • Based on Dmitry Shkarin’s PPMd var.H
  • Used in 7z archives
  • Order: 2-64

PPMd Variant I (PPMd8)

Improved PPMd algorithm from 2002
  • Based on Dmitry Shkarin’s PPMd var.I
  • Better compression ratio
  • Order: 2-16
PPMd is particularly effective for:
  • Text files (source code, logs, documents)
  • Structured data (CSV, JSON, XML)
  • Database dumps
  • Configuration files
For these file types, PPMd often achieves 5-20% better compression than LZMA.

How PPMd Works

PPMd uses Prediction by Partial Matching:
  1. Context Modeling: Analyzes previous bytes to build statistical models
  2. Probability Prediction: Predicts the probability of each possible next byte
  3. Arithmetic Coding: Encodes bytes using their predicted probabilities
  4. Adaptive Learning: Updates models as more data is processed
PPMd maintains multiple context models of different lengths (orders):
Higher orders provide better compression for structured data but require more memory.
When a byte is not found in the current context, PPMd uses an “escape” mechanism:
This allows the algorithm to fall back to lower-order contexts when needed.

PPMd7 (Variant H)

PPMd var.H is the original PPMd implementation used in 7z archives.

Parameters

Type: unsigned
Range: PPMD7_MIN_ORDER (2) to PPMD7_MAX_ORDER (64)
Default: 6
Maximum context length for prediction.
  • Low order (2-4): Faster, less memory, lower compression
  • Medium order (6-8): Balanced (recommended)
  • High order (16-64): Best compression for structured text
For most text files, order 6-8 provides the best balance. For highly structured data like source code, try order 10-16.
Type: UInt32
Range: PPMD7_MIN_MEM_SIZE (2 KB) to PPMD7_MAX_MEM_SIZE (~4 GB)
Default: 16 MB
Amount of memory allocated for context models.Typical settings:
  • 1-4 MB: Fast, lower compression
  • 16-64 MB: Good balance (recommended)
  • 128-256 MB: Maximum compression for large text files
Both encoder and decoder require the same amount of memory. Large memory settings may cause issues on memory-constrained systems.

Memory Requirements

PPMd7 memory usage:
  • Encoding: Same as memory size parameter
  • Decoding: Same as memory size parameter
  • Stack: Minimal (< 1 KB)
Example configurations:
  • Order 6, 16 MB: ~16 MB RAM (both compress/decompress)
  • Order 8, 64 MB: ~64 MB RAM (both compress/decompress)
  • Order 16, 256 MB: ~256 MB RAM (both compress/decompress)

API Usage

Decoding

PPMd8 (Variant I)

PPMd var.I is an improved version with better compression ratio.

Key Differences from PPMd7

PPMd8 has a lower maximum order:
This is due to improved context modeling that provides better compression with lower orders.
PPMd8 supports different memory restoration methods:
  • RESTART: More aggressive memory recycling
  • CUT_OFF: Conservative memory management
FREEZE mode is disabled due to compatibility issues between PPMdI rev.1 and rev.2.
PPMd8 uses different statistical models:
These provide better probability estimation for certain data patterns.

API Usage

Performance Characteristics

Typical performance on modern hardware (Intel Core i7, 3.5 GHz):Compression:
  • Order 6, 16 MB: ~1-2 MB/s
  • Order 8, 64 MB: ~0.5-1 MB/s
  • Order 16, 256 MB: ~0.3-0.5 MB/s
Decompression:
  • Order 6: ~5-10 MB/s
  • Order 8: ~3-7 MB/s
  • Order 16: ~2-5 MB/s
Compression ratio (vs LZMA):
  • Text files: 5-20% better
  • Source code: 10-25% better
  • Binary executables: Similar or worse
  • Multimedia: Much worse (use LZMA)

Compression Ratio Comparison

For large text archives, PPMd can save 10-20% space compared to LZMA.
PPMd is not recommended for binary executables. Use LZMA2 with BCJ filter instead.

Command Line Usage

Recommended settings by file size:
  • Small files (< 1 MB): -mo=4 -mmem=4m
  • Medium files (1-10 MB): -mo=6 -mmem=16m
  • Large files (10-100 MB): -mo=8 -mmem=64m
  • Huge files (> 100 MB): -mo=10 -mmem=128m

Best Practices

Higher order = better compression but slower and more memory:
  1. Start with order 6 (default)
  2. For highly structured data, try order 8-10
  3. For maximum compression, test up to order 16
  4. Monitor compression time and memory usage
Memory should be:
  • At least 1-2x the file size for small files
  • 10-20% of file size for large files
  • Minimum 4 MB for order 6+
  • Maximum what both encoder and decoder can allocate
Decoder needs the same memory as encoder. Don’t use 256 MB if decoder only has 64 MB available.
Avoid PPMd for:
  • Already compressed data: JPEG, PNG, MP3, video files
  • Binary executables: Use LZMA2 with BCJ filter
  • Random data: Any method will fail
  • Memory-constrained systems: Use LZMA2 or Deflate
  • Need for speed: Use LZMA2 with multithreading

Error Codes

PPMd7 vs PPMd8

For most use cases, PPMd7 (var.H) is recommended as it’s the standard PPMd implementation in 7z archives.

See Also