Repository navigation
perf(encoding): optimal-parser workspace in upstream's shape - #686
Conversation
The optimal parser's per-position candidate buffer held the shared MatchCandidate, whose start position the parser never reads: 12 bytes a candidate on 32-bit targets, 24 on 64-bit, against upstream's 8-byte ZSTD_match_t. Its 4104-entry room now holds OptMatch, two u32s, the shape of ZSTD_match_t; the lazy finders keep MatchCandidate. Part of #684
The optimal pass wrote a whole block's plan before handing it to the sequence sink, in room for block/3 + 1 sequences: 512 KiB of the context for 128 KiB blocks, beside the block's own sequence buffer of the same count. Upstream stores each segment's sequences into seqStore before the next segment and keeps no block plan. The room now holds one segment's sequences. The block pass stops when the next segment might not fit; its caller hands the plan so far to the sink and enters the pass again where it stopped, the pass's position (cursor, pending literals, repeats, statistics cursor) set once per block by the caller and kept in the pass buffers. The plan replay continues from where the last run ended and the block's trailing literals close it. Part of #684
Room for one segment stopped the block pass after every segment that wrote a sequence, and on compressible input a segment often ends at its first match: 2.9% more instructions at level 16 on a 1 MiB corpus file. Two segments' worth, capped by the block, stops it once per segment's worth of sequences. Part of #684
Called in the plan hand-over loop, the AVX2 block pass was inlined into the match driver (start_matching_owned), and the merged body ran 20M more instructions on two 1 MiB corpus frames at level 16 (243M against 223M for the pass on its own). Each tier's pass is #[inline(never)], one out-of-line body entered from the loop. Part of #684
The room check took a min and a division by three at every segment, and on input without matches a segment is about one literal. The length past which the pass stops is fixed per entry: the room less a segment's worth, or never where the room holds the whole block's. A segment pays one comparison. Part of #684
The stop length was a local live across the segment loop, and the pass body, already short of registers, ran 2% more instructions at level 19 on a 1 MiB corpus file (callgrind: 311.9M against 305.8M). It sits with the rest of the pass state in the pass buffers, read once a segment. Part of #684
The block pass takes the cursor, pending literals and repeats as arguments again and writes them into the pass state on entry; its caller passes the saved position on every entry and keeps only the statistics cursor across them. Level 16 on a 1 MiB corpus file: 0.1% more instructions than before the plan room changed (was 0.5%), cycles level. Part of #684
- A position with no tree candidate inside the window becomes a leaf at once (both sides cleared, insert cursor as the walk's fall-through sets it) instead of reaching the walk's exit, whose register set-up the merge paid on nearly every position of incompressible input. With a primed dictionary tree the walk path is unchanged. - The block's end and the pass's sufficient match length are set on the generator as the optimal pass enters and read by the search, so the per-position call carries two arguments fewer. Output is byte-identical (CLI frames at levels 12-22, four fixtures). Part of #684
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. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
## 🤖 New release * `structured-zstd`: 0.4.2 -> 0.4.3 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.4.3](v0.4.2...v0.4.3) - 2026-11-21 ### Performance - *(encoding)* fewer memcpy calls on small dictionary frames ([#691](#691)) - *(encoding)* cheaper dictionary frames at negative levels ([#687](#687)) - *(encoding)* optimal-parser workspace in upstream's shape ([#686](#686)) - *(decoding)* sequence loop common path in assembly on x86_64 ([#683](#683)) - *(decoding)* set sequence table counters in one pass ([#682](#682)) - *(decoding)* four-stream literals in a machine word, asm loop on 32-bit x86 ([#681](#681)) - *(decoding)* four-stream literal loop in assembly ([#679](#679)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: sw-release-bot[bot] <255865126+sw-release-bot[bot]@users.noreply.github.com>
Summary
Changes
OptMatch { offset: u32, match_len: u32 }replaces the three-word candidate in the search, the DP and the LDM candidate path.Output is byte-identical at every optimal level.
Testing
Tests, lints and formatting pass on aarch64 and x86_64; compressed frames compared against main at levels 12-22 on four fixtures. Interleaved A/B against main: i686 1 KiB random frames about -5% cycles (L12/13/19), x86_64 1 KiB -3..4% (L13/19), i686 10 KiB L13 -12%, z000033 x86_64 L16 about -3%, no level slower.
Closes #684
Summary by CodeRabbit