Method ID
ID:21 (hex)
The LZMA2 method is identified by the single-byte value 21 in 7z archive format.
Overview
LZMA2 improves upon LZMA with:- Full multithreading support (multiple cores)
- Better handling of incompressible data
- Ability to store uncompressed chunks
- Support for resetting compression state
- Smaller overhead for small compressed chunks
LZMA2 is the default and recommended compression method for 7z archives. It provides the best balance of compression ratio, speed, and multithreading efficiency.
Key Improvements Over LZMA
Multithreading Support
Multithreading Support
LZMA2 divides data into independent chunks that can be compressed in parallel:
- LZMA: Limited to 2 threads (match finding only)
- LZMA2: Supports unlimited threads (full parallel compression)
Incompressible Data Handling
Incompressible Data Handling
LZMA2 can detect incompressible data and store it uncompressed:This prevents expansion of incompressible data (like JPEG, MP3, etc.)
Dictionary Reset
Dictionary Reset
LZMA2 can reset the dictionary between chunks:
- Allows better parallel decompression
- Reduces memory usage for random access
- Enables streaming compression
Dictionary reset slightly reduces compression ratio but enables important features like multithreading and random access.
Smaller Property Overhead
Smaller Property Overhead
LZMA2 properties are encoded more efficiently:
- LZMA: 5-byte header per stream
- LZMA2: 1-byte properties + control bytes per chunk
Compression Parameters
LZMA2 uses the same base parameters as LZMA, wrapped inCLzma2EncProps:
LZMA2 Properties Structure
LZMA2 Properties Structure
- Default: Calculated based on dictionary size
- Range: Up to
LZMA2_UNPACK_SIZE_MAX(2 MB) - Smaller blocks = better multithreading, slightly lower ratio
numBlockThreads: Threads per block (1-2)numTotalThreads: Total parallel blocks- Total threads =
numBlockThreads * numTotalThreads
Dictionary Size
Dictionary Size
Range:
Default: Based on compression levelSame as LZMA, but LZMA2 properties byte encodes it differently:
(1 << 12) to (1 << 30) (1.5 GB for 64-bit)Default: Based on compression levelSame as LZMA, but LZMA2 properties byte encodes it differently:
| Prop | Dict Size |
|---|---|
| 40 | 2 GB |
| 39 | 1.5 GB |
| 38 | 1 GB |
| 37 | 768 MB |
| 36 | 512 MB |
| 35 | 384 MB |
| 34 | 256 MB |
| … | … |
| 28 | 16 MB |
lc, lp, pb Constraints
lc, lp, pb Constraints
LZMA2 Restriction: This is stricter than LZMA to ensure efficient encoding. Default values (lc=3, lp=0) satisfy this constraint.
lc + lp <= LZMA2_LCLP_MAX (4)Memory Requirements
Encoding
Memory per thread:Example: Level 5 (16 MB dict) with 4 threads:
- Per thread: ~190 MB
- Total: ~760 MB
- Per thread: ~2.9 GB
- Total: ~11.6 GB
Decoding
Memory for decompression:- Much lower than encoding
- Single-threaded decompression
- Chunk buffer: Up to 2 MB
Stream Format
Each LZMA2 stream consists of chunks with control bytes:API Usage
Encoding
Decoding
Performance Characteristics
Typical performance on modern hardware (Intel Core i7 quad-core, 3.5 GHz):Compression (4 threads):
- Level 5: ~8-12 MB/s (4x speedup)
- Level 9: ~4-6 MB/s (3-4x speedup)
- Similar to LZMA: ~2-3 MB/s (level 5)
- ~20-40 MB/s (single-threaded)
- Same as LZMA
- Nearly identical to LZMA
- 0-2% larger due to chunk overhead
- Better than LZMA for incompressible data
Multithreading Efficiency
| Threads | Speedup | Efficiency |
|---|---|---|
| 1 | 1.0x | 100% |
| 2 | 1.8x | 90% |
| 4 | 3.2x | 80% |
| 8 | 5.5x | 69% |
| 16 | 9.0x | 56% |
Efficiency decreases with more threads due to:
- Chunk synchronization overhead
- Dictionary reset between chunks
- Memory bandwidth limitations
Command Line Usage
LZMA vs LZMA2 Comparison
| Feature | LZMA | LZMA2 |
|---|---|---|
| Method ID | 03 01 01 | 21 |
| Multithreading | Limited (2 threads) | Full (unlimited) |
| Incompressible data | Can expand | Stores uncompressed |
| Dictionary reset | No | Yes |
| Random access | No | Possible |
| Compression ratio | Excellent | Excellent (0-2% larger) |
| Encoding speed | 2-3 MB/s | 8-12 MB/s (4 threads) |
| Decoding speed | 20-40 MB/s | 20-40 MB/s |
| Memory (compress) | High | High * threads |
| Memory (decompress) | Medium | Medium |
| File format | .lzma, .7z | .7z, .xz |
| Streaming | Yes | Yes |
Best Practices
Choosing Thread Count
Choosing Thread Count
Recommended thread count:
- Desktop PC: Number of CPU cores
- Server: Half of CPU cores (leave resources for other tasks)
- Low memory: Reduce threads to fit memory budget
Dictionary Size Selection
Dictionary Size Selection
General rule: Dictionary should be 4-16x the size of typical files
- Small files (< 1 MB): 1-4 MB dictionary
- Medium files (1-10 MB): 16-64 MB dictionary
- Large files (> 10 MB): 64-256 MB dictionary
- Huge files (> 100 MB): 256 MB - 1.5 GB dictionary
Memory Budget Management
Memory Budget Management
Calculate required memory before compression:Example configurations:
- 4 GB RAM: -md=32m -mmt=2
- 8 GB RAM: -md=64m -mmt=2 or -md=32m -mmt=4
- 16 GB RAM: -md=128m -mmt=2 or -md=64m -mmt=4
- 32 GB RAM: -md=256m -mmt=2 or -md=128m -mmt=4
See Also
- LZMA Compression - Original single-threaded version
- Compression Methods Overview - Compare all methods
- PPMd Compression - Alternative for text files
- Source files:
C/Lzma2Enc.c,C/Lzma2Enc.h,C/Lzma2Dec.c,C/Lzma2Dec.h