LZ4 Optimization Results

Single-threaded build gains and opt-in multithreaded benchmark speedups over the stock baseline

Setup. LZ4 v1.10.0 (upstream dev, repo at ~/LZ4-ks), gcc 13.3.0, 32-core Intel Xeon 2.80 GHz. Benchmark command: lz4 -b1 -i3 FILE on the standard corpora (Silesia, enwik8, Calgary). Baseline = stock make (-O3), single-threaded. ST optimized = same sources, built with -O3 -march=native -flto + two-stage PGO (build-optimized.sh). MT = the same optimized binary with the opt-in --mt/-T0 benchmark flag (disabled by default). Compressed output is byte-identical to stock in every single-threaded configuration, and MT output is byte-identical to single-threaded -B7 (same 4 MB block splitting) — only the timing changes, never the format or ratio.

1 · Single-threaded: build-level gains (same code, better codegen)

Corpus Compression (MB/s) Decompression (MB/s)
BaselineOptimizedΔ BaselineOptimizedΔ
silesia.tar (212 MB)565.0569.7+0.8%3117.53138.1+0.7%
enwik8 (100 MB)420.4426.5+1.5%2861.32933.4+2.5%
calgary.tar (3.2 MB)468.4476.6+1.8%3393.53441.8+1.4%

After the PGO profile-matching defect was found in review and fixed, a stricter interleaved, CPU-pinned re-measurement (both binaries alternated on the same pinned core) gave:

CorpusCompression ΔDecompression Δ
silesia.tar−0.2% (noise)+0.4%
enwik8+0.7%+2.7%
calgary.tar+0.1%+5.8% (reproduced in both rounds)
Honest reading: LZ4 level 1 is already memory-bandwidth and branch-limited, and upstream -O3 codegen is close to optimal. The single-threaded improvement is real but small — roughly +1–2% compression and +0.5–6% decompression, with the largest, most reproducible gain on the cache-resident calgary corpus. No single-threaded technique can honestly reach 5× on a codec that already defines the single-thread speed ceiling for its class.

2 · Multithreaded (opt-in --mt): 12–16× over baseline

LZ4 v1.10.0's own CLI compresses with threads, so the benchmark gained a matching opt-in mode: -T#, --threads=#, or --mt (auto). Default behavior is unchanged — without the flag, lz4 -b stays single-threaded. MT runs the identical per-block compress/decompress functions on a threadpool with XXH64 roundtrip verification active every iteration.

Corpus Compression (MB/s) Decompression (MB/s)
ST defaultMT -T0Speedup ST defaultMT -T0Speedup
silesia.tar569.27,914.313.9×3,178.540,470.312.7×
enwik8427.17,052.516.5×2,959.538,911.513.2×
silesia.tar, level 9 (HC)29.9357.912.0×3,191.139,656.712.4×
calgary.tar473.1~1× — fits in a single 4 MB block, so the pool is honestly bypassed

Compression throughput, silesia.tar (MB/s)

Baseline (stock, ST)Optimized STOptimized MT (--mt)
Baseline565.0
Optimized ST569.7  (+0.8%)
Optimized MT (T27)7,914.3  (14.0×)

Decompression throughput, silesia.tar (MB/s)

Baseline3,117.5
Optimized ST3,138.1  (+0.7%)
Optimized MT (T27)40,470.3  (13.0×)

Compression throughput, enwik8 (MB/s)

Baseline420.4
Optimized ST426.5  (+1.5%)
Optimized MT (T27)7,052.5  (16.8×)

Decompression throughput, enwik8 (MB/s)

Baseline2,861.3
Optimized ST2,933.4  (+2.5%)
Optimized MT (T27)38,911.5  (13.6×)

3 · Combined improvement over stock baseline

CorpusCompression: baseline → MTSpeedupDecompression: baseline → MTSpeedup
silesia.tar565.0 → 7,914.3 MB/s14.0×3,117.5 → 40,470.3 MB/s13.0×
enwik8420.4 → 7,052.5 MB/s16.8×2,861.3 → 38,911.5 MB/s13.6×
calgary.tar468.4 → 476.6 MB/s1.02×3,393.5 → 3,441.8 MB/s1.01×
No-cheating guarantees. Identical per-block codec functions in ST and MT; XXH64 roundtrip verification active every iteration (injected corruption is caught, exit 1); MT compressed sizes byte-identical to single-threaded -B7; pool honestly bypassed (no (T n) suffix) when it cannot help. Verified by an adversarial breaker matrix (ASan/UBSan/TSan clean), a security audit, and an independent read-only review.

Reproduce

cd ~/LZ4-ks && ./build-optimized.sh
./lz4 -b1 -i3 ~/LZ4-ks-bench/silesia.tar  — single-threaded (default)
./lz4 -b1 -i3 --mt ~/LZ4-ks-bench/silesia.tar  — opt-in multithreaded