Summary
The current Fastest level encoder uses a basic hash table matcher. The C reference zstd_fast.c employs a pipeline-style interleaving pattern that hides memory latency — the single biggest optimization for compression speed.
C reference optimizations (zstd_fast.c)
Pipeline-style hash+lookup interleaving
The C code interleaves operations across multiple positions to hide memory latency:
Position N: ... Match
Position N+1: ... TableLookup Match
Position N+2: Read Hash TableLookup Match
Position N+3: Hash TableLookup Match
While waiting for hash table lookup result for position N, the code is already computing hash for position N+1 and reading data for position N+2. This keeps the CPU pipeline full.
Match length counting
ZSTD_count(): Compare 8 bytes at a time using MEM_read64() XOR + CTZ
- Processes
sizeof(size_t) bytes per iteration on 64-bit systems
- Final cleanup for remaining bytes
Hash fill strategies
fastHashFillStep = 3: Only every 3rd position gets hash entry (speed vs. ratio trade-off)
- Dictionary fill: every position (accuracy matters more for small data)
Rep code checking
- Before hash lookup: check if repeat offset matches at current position
- Repeat matches are free (0-bit offset encoding) — huge ratio win
Current Rust implementation
encoding/match_generator.rs — basic sequential hash lookup
- No pipeline interleaving
- Match counting likely byte-by-byte or small chunks
- Rep code handling: offset history hardcoded
[1, 4, 8], not updated during encoding (compressed.rs:27)
What needs to be implemented
- Pipeline-style interleaving — prefetch next hash while processing current match
- Bulk match counting — 8-byte XOR + trailing_zeros for O(8) bytes per iteration
- Rep code optimization — check repeat offsets before hash lookup
- Offset history tracking — update
[rep0, rep1, rep2] during encoding (currently broken)
- Hash fill step tuning — configurable fill rate for speed vs ratio
Performance impact estimate
- Pipeline interleaving: ~20-30% compression speed improvement
- Bulk match counting: ~10-15% on match-heavy data
- Rep codes: ~5-15% better compression ratio (free matches)
Acceptance criteria
Time estimate
2d
Summary
The current
Fastestlevel encoder uses a basic hash table matcher. The C referencezstd_fast.cemploys a pipeline-style interleaving pattern that hides memory latency — the single biggest optimization for compression speed.C reference optimizations (zstd_fast.c)
Pipeline-style hash+lookup interleaving
The C code interleaves operations across multiple positions to hide memory latency:
While waiting for hash table lookup result for position N, the code is already computing hash for position N+1 and reading data for position N+2. This keeps the CPU pipeline full.
Match length counting
ZSTD_count(): Compare 8 bytes at a time usingMEM_read64()XOR + CTZsizeof(size_t)bytes per iteration on 64-bit systemsHash fill strategies
fastHashFillStep = 3: Only every 3rd position gets hash entry (speed vs. ratio trade-off)Rep code checking
Current Rust implementation
encoding/match_generator.rs— basic sequential hash lookup[1, 4, 8], not updated during encoding (compressed.rs:27)What needs to be implemented
[rep0, rep1, rep2]during encoding (currently broken)Performance impact estimate
Acceptance criteria
Time estimate
2d