Setting Parameters
UseZSTD_CCtx_setParameter() to configure compression parameters:
Compression Level
The compression level is the primary control for the compression ratio vs. speed tradeoff.- Range: Negative values to 22
- Default: 3 (
ZSTD_CLEVEL_DEFAULT) - Special: 0 means “use default”
Window Size
The window size controls the maximum back-reference distance for finding matches.- Power of 2: windowLog=20 means window size = 2^20 = 1 MB
- Range:
ZSTD_WINDOWLOG_MINtoZSTD_WINDOWLOG_MAX - Default: 0 (automatic based on source size)
- Impact: Larger windows improve compression but use more memory
Compression Strategies
Strategies control the algorithm used to find matches.Fast strategies (fast, dfast)
Best for speed-critical applications:
- Minimal CPU usage
- Lower compression ratios
- Good for real-time compression
Lazy strategies (greedy, lazy, lazy2)
Balanced performance:
- Moderate CPU usage
- Good compression ratios
- Default for mid-range levels
Hash and Chain Tables
These parameters control internal data structures for match finding.Hash Log
- Size: Hash table size = 2^hashLog entries
- Memory: (1 << (hashLog+2)) bytes
- Impact: Larger tables improve ratio for fast/dfast strategies
- Range:
ZSTD_HASHLOG_MINtoZSTD_HASHLOG_MAX
Chain Log
- Size: Chain table size = 2^chainLog entries
- Memory: (1 << (chainLog+2)) bytes
- Impact: Larger tables improve ratio but slow compression
- Note: Useless for “fast” strategy, useful for “dfast” as secondary probe table
Search Log
- Attempts: Number of search attempts = 2^searchLog
- Impact: More attempts = better ratio, slower compression
- Note: Useless for “fast” and “dfast” strategies
Match Parameters
Minimum Match Length
- Range:
ZSTD_MINMATCH_MIN(3) toZSTD_MINMATCH_MAX(7) - Default: Depends on strategy (typically 4-6)
- Impact: Larger values increase speed but may decrease ratio
Target Length
- btopt/btultra/btultra2: Length considered “good enough” to stop search
- Larger values = stronger/slower compression
- fast: Distance between match sampling
- Larger values = faster/weaker compression