Repository navigation
perf(encoding): attached dictionary tree at the CDict's hashLog - #704
Conversation
The binary-tree backend hashed an attached dictionary into a table sized from the dictionary's length (ceil_log2 of it, clamped to the frame's hashLog), while upstream walks dms->hashTable at the dictionary's own cParams, and the Fast and Dfast backends already take the CDict's geometry. On a small dictionary the length rule ran a bit under the CDict's: a 1280-byte dictionary at level 11 (a btopt CDict of hashLog 12) got 11 bits, its buckets were half full on random input against a fifth for upstream, and the search's empty-bucket test mispredicted twice as often (923 against 470 mispredicted taken branches per profile on i686), with more colliding dictionary nodes walked after it. The frame's reset now hands the HashChain backend the resolved CDict hashLog, which the dictionary tree is built at; the length-based sizing and its tests are gone. Regression test: driver_bt_dictionary_table_takes_the_cdict_hash_log. Closes #703
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36758667f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
zstd 1.6.0 takes ZDICT_tryMerge's included-entry length difference (MAX(elt.length - table[u].length, 1)) in unsigned 32-bit arithmetic where 1.5.7 cast both to int, so an entry longer than the new element adds a wrapped length to its savings, and the product is size_t. The trainer now does the same at pointer width; against 1.5.7's rule it chose different content on the unit-file fixture (4091 bytes against the reference's 3941), which failed legacy_trainer_ffi on every test job. ffi-bench now requires zstd-sys 2.2 (zstd 1.6.0): the benchmarks and interop tests resolve the newest release anyway, the floor makes the reference they run against a requirement rather than an accident of resolution. Part of #705
The reference moves to zstd 1.6.0 everywhere it was pinned to 1.5.7: the vendored zstd.h (zdict.h and zstd_errors.h are unchanged), the version the C ABI and pkg-config report (10600, "1.6.0"), the release the conformance scripts and the c-abi job build, and the command line the CLI follows. Following 1.6.0's API changes: - ZSTD_isDeterministicBuild() is exported. It returns 0: this encoder's frames are its own, so it does not belong to the builds whose output matches libzstd 1.6.0 byte for byte. - ZSTD_copyCCtx() and ZSTD_copyDCtx(), removed upstream, are removed here with the state kept only for them. - v0.5-v0.7 frames are no longer read by default, as libzstd stopped building that support by default (ZSTD_LEGACY_SUPPORT=0). The codec's `legacy` feature leaves `default`; the C ABI gains a `legacy` feature forwarding it, and without it such a frame is not a frame (ZSTD_isFrame 0, prefix_unknown), which a test pins. CI runs the decoder and command-line tests, the C ABI tests and the decode_legacy fuzz target with the feature on; the decoder step now builds the command line too, which its filter named but never compiled. BREAKING CHANGE: the default build no longer decodes v0.5-v0.7 frames; enable the `legacy` feature to keep reading them. The C ABI no longer exports ZSTD_copyCCtx and ZSTD_copyDCtx. Part of #705
Upstream 1.6.0's own suites (tests/playTests.sh and every case of tests/cli-tests the conformance script runs) pass against the command line. What they required: - --filelist keeps a CR before the newline as part of the name except on native Windows, where CRLF ends a line. - -f replaces a symbolic link standing at the output name with a regular file, never writing through it; without -f such an output is refused. - -l says "reached end of file with incomplete (skippable) frame" for an empty file or a header cut short, and "seeked to position N, which is beyond file size of M" for a skippable frame whose payload runs past the end. - --output-dir-flat refuses any two inputs that would share an output, with or without --rm, before anything is written: each shared name, then "no files were processed". - -M bounds the decode window at any value, as ZSTD_DCtx_setMaxWindowSize does upstream: a lower limit refuses the frames that pass it when they are decoded instead of refusing the limit itself. A plain decode's -D dictionary is weighed alone against it; benchmarks and training keep their accounting. The value is a 32-bit field, so 4 GiB overflows, and the numeric error lists the G suffixes. - Training refuses more samples than an int count and a size_t length table hold, with status 14, before any sample is read. - Help text, the too-few-samples advice and the refusal of an output that is an input take 1.6.0's wording; -vvV says the build is non-deterministic (its frames are not libzstd's byte for byte) and -vV lists legacy support when it is built in. Part of #705
`frame_header_size`'s doc linked `LegacyVersion::header_size`, which exists only with `legacy`; with the feature out of `default` the docs build (RUSTDOCFLAGS=-D warnings) failed on the broken link. The method is named without a link, and `legacy` joins the docs.rs feature set and the CI rustdoc run that mirrors it, so the public docs keep the type; the private-items run stays without it and covers the other configuration. Part of #705
cltools/zstdless.sh exercises the reference's two-line zstdless script, which this project does not ship, through the host's less, and expects the exit status of an older less: less 710 exits 1 on a missing file, so the case fails on such hosts with the reference binary as well. It checks nothing this command decides. Part of #705
The zstdless case runs again. Its bad-path step ran under set -e and so asserted the exit status of less, which zstdless execs: less 668 exits 0 on a missing file, less 710 exits 1, with the reference binary too. The conformance script lets that one step fail; the case still compares stdout and stderr, including this command's "can't stat" message, and the good-path steps keep set -e. The script stops if the step changes shape upstream. Part of #705
Bash 5.2 expands an unquoted & in a ${var/pat/rep} replacement to the
matched text, so the adjusted step's >&2 became a bad descriptor. Both
sides of the replacement are quoted now.
Part of #705
The ${var/pat/rep} replacement kept its inner quotes literally under the
bash 3.2 that macOS runs, turning the adjusted step into one quoted word
and failing with "command not found". The test is rewritten line by
line now, which behaves the same under bash 3.2 and 5.2.
Part of #705
A reused compressor whose hash_log changed between frames kept the attached dictionary tree at the previous CDict width: on small frames the live widths are capped by the source and stay the same, so the reset re-borrowed the primed tree without the build's shape check. A primed tree whose width differs from the frame's CDict is now dropped before the reset, as the Fast backend's set_dict_table_hash_log does. Regression test driver_bt_dictionary_tree_follows_a_changed_cdict_hash_log (1280-byte dictionary, level 11, 256-byte frames, hash_log 11 then 12). Part of #703
- A set of dictionaries (`reset_with_dict_handles`, `decode_all_with_dict_handles`, the C ABI's ZSTD_d_refMultipleDDicts) gives a frame naming a nonzero ID that entry and fails with DictNotProvided without one; a frame naming none or ID 0 takes the entry of ID 0, or no dictionary. It took the last entry instead, so a frame naming no dictionary decoded with an unrelated one (upstream 1.6.0 `ZSTD_DCtx_getFrameDDict`). One dictionary handed in alone (`*_with_dict_handle`, the C ABI's loaded, single referenced and prefix dictionaries) still applies to a frame naming none. - The C ABI's raw-content decode dictionary has ID 0, as upstream's raw-content DDict has, so it is the set entry such a frame takes. - Turning ZSTD_d_refMultipleDDicts off drops the set, as upstream clears its DDict set; its entries were still used. - A skippable frame read through ZSTD_decompressStream spends a referenced prefix, as upstream resolves the frame's dictionary before telling a skippable header apart; the prefix outlived it. - `-l`'s skippable-frame end is computed with the bound it relies on asserted in debug builds; the `-D` check under `-M` and `--version` get tests; the README feature table shows `legacy` off by default. Regression tests: dict_set_takes_the_id_zero_entry_for_a_frame_naming_none, single_ddict_decodes_a_frame_naming_no_dictionary, disabling_multiple_ddicts_releases_the_set, a_skippable_frame_spends_the_prefix, a_decode_dictionary_fits_a_limit_covering_both_copies. BREAKING CHANGE: reset_with_dict_handles and decode_all_with_dict_handles no longer apply the last dictionary to a frame naming none; they take the entry of ID 0, or decode without a dictionary, and a frame naming an ID the set lacks fails with DictNotProvided instead of DictIdMismatch. Part of #705
Summary
hashLog, as upstream walksdms->hashTableat the dictionary's own cParams and as the Fast and Dfast backends already do. It used a width sized from the dictionary's length, which ran a bit under the CDict's on small dictionaries.hashLog12) the old width was 11 bits: the buckets were half full on random input against a fifth for upstream, the search's empty-bucket test mispredicted about twice as often, and more colliding dictionary nodes were walked.Effect, 10 KiB of random input with its trained dictionary, cycles against main (Broadwell, interleaved rounds):
Levels 13, 16 and 19, and 4 KiB log frames with their dictionary at every level, are unchanged in time.
Output
Frames compared against the parent at levels 9-22 over text, datagen and random input, 1280-byte, 16 KiB and 110 KiB dictionaries, 1 KiB and 10 KiB frames: identical except four level-13 cells on text, each the same size or smaller and closer to libzstd 1.6.0 (dictionary / frame: 16 KiB / 1 KiB 515 -> 510 bytes, libzstd 507; 110 KiB / 1 KiB 468 -> 457, libzstd 451; 110 KiB / 10 KiB 3454 -> 3452, libzstd 3452; 16 KiB / 10 KiB unchanged size). Hash width changes which colliding nodes the bounded walk visits, so the output is not byte-identical.
Changes
MatchTable::dict_table_hash_log: the CDict'shashLog, set by the frame's reset from the resolved dictionary tables;prime_dms_btbuilds the dictionary tree at it, and a primed tree of another width is dropped before the reset re-borrows it.dms_hash_logand its tests are removed.driver_bt_dictionary_table_takes_the_cdict_hash_loganddriver_bt_dictionary_tree_follows_a_changed_cdict_hash_log.Testing
Library tests, formatting, clippy and rustdoc pass locally; CI runs the full matrix.
Closes #703
Summary by CodeRabbit