Repository navigation
Add advanced compression parameters (Part of #118) - #121
Merged
Merged
Conversation
Setters on Compressor, StreamEncoder and Encoder for every libzstd compression parameter: strategy, window, hash, chain and search log, minimum match, target length and literal compression mode (ZSTD_c_strategy ... ZSTD_c_literalCompressionMode). Each overrides one parameter of the level's set (ZSTD_overrideCParams); the output is byte-identical to libzstd 1.6.0's with the same level and parameters. New public types Strategy and LiteralCompression, and Error::ParameterOutOfBound for the values libzstd rejects. Defaults and default output are unchanged. StreamEncoder::set_window_log is now public and returns a Result instead of panicking. Ported along the way: - the optimal parser prices literals at 8 bits and keeps no literal statistics when literal compression is disabled (ZSTD_compressedLiterals); done with zero frequencies and a base price, so the per-position price code is unchanged; - the jobs of a multithreaded frame after the first take the literal mode too. Tests: tests/cparams.rs compares random parameter sets over the whole valid range with libzstd: one-shot on a reused context, streaming with flushes, loaded and prepared dictionaries, multithreading, the setter bounds and mid-frame errors. 64 seeds x 1500 sets pass on the EPYC host. Benchmarks (EPYC 7543, 16 lanes, interleaved binary copies): - default path, main vs branch: identical output, geomean speed 1.001 over 163 file/level/chunk cases; perf stat instruction counts identical. The ~1% at L-5/L-1/L7 is copy placement: three copies of main differ by up to 5.5% (nci L7); medians over copies are level. - against zrip at zrip's ratio (84 points): zstd-native levels 0.91x, libzstd + parameters 0.94x, zstd-native + parameters 1.00x. - decoding Huffman literals at negative levels: 0.74x the speed of raw literals (1.1-2.3 GB/s), for much better ratios. profile_encode: ZSTD_BENCH_CPARAMS applies to native too. profile_decode: ZSTD_BENCH_LIT=1 enables Huffman literals.
This was referenced Dec 4, 2026
zcsizmadia
added a commit
that referenced
this pull request
Dec 5, 2026
#122) The compress target now also sets the parameters added in #121: strategy, hash, chain and search log, minimum match, target length and literal compression mode, each left at the level's value a third of the time, on both libzstd (ZSTD_CCtx_setParameter) and zstd-native (StreamEncoder and Compressor setters). The new field comes after the dictionary in EncParams, so existing corpus entries keep their meaning. The one-shot path no longer needs the level's window log: Compressor has set_window_log now. Inputs are capped at 48 KiB from btlazy2 on (by level or strategy), and hash and chain logs at 20. 32 workers for 10 minutes on the EPYC host (~3.7M inputs): no mismatch, no crash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #118.
What
Setters on
Compressor,StreamEncoderandEncoderfor every libzstd compression parameter:set_strategy,set_window_log,set_hash_log,set_chain_log,set_search_log,set_min_match,set_target_length;set_literal_compression(Auto/Enabled/Disabled).Each overrides one parameter of the level's set (
ZSTD_overrideCParams). The output is byte-identical to libzstd 1.6.0's with the same level and parameters (ZSTD_compress2/ZSTD_compressStream2afterZSTD_CCtx_setParameter).Other API changes:
StrategyandLiteralCompression;Error::ParameterOutOfBoundfor the values libzstd rejects;StreamEncoder::set_window_logwas hidden and panicked on an invalid value. It is now public and returns aResult.StreamEncoderreturnsStageWrongif a parameter is changed mid-frame; libzstd allows some changes there, so this is stricter. Defaults and default output are unchanged.Ported along the way
The new differential tests found two bugs:
ZSTD_compressedLiterals). This is done with zero frequencies and a base price, so the per-position price code is unchanged.Tests
New
tests/cparams.rscompares random parameter sets over the whole valid range against libzstd:ZSTD_CCtx_setParameter, and the mid-frame errors.ZSTD_NATIVE_CPARAMS_ITERSandZSTD_NATIVE_CPARAMS_SEEDwiden the search. 64 seeds × 1,500 sets pass on the EPYC host. The workspace and portable suites pass there too.Benchmarks
EPYC 7543, 16 lanes (one core per L3 domain), interleaved binary copies.
Default path, main vs this branch: identical output in every case.
perf statinstruction counts are identical (ratio 1.0000).(cycles relative to main copy a; lower is faster)
Against zrip, at zrip's ratio. Speed on the Pareto frontier at each zrip point's ratio, divided by zrip's speed (5 rounds; levels -64 to 1, with and without
lit=on,mml=7/lit=on,mml=6):Decoding Huffman literals at negative levels (zstd-native decoder, frames from libzstd with and without
ZSTD_c_literalCompressionMode=enable):Bench tools
profile_encode:ZSTD_BENCH_CPARAMSnow applies tonativetoo.profile_decode:ZSTD_BENCH_LIT=1turns on Huffman literals.Not in this PR
A fuzz target with these parameters (follow-up).