perf(encode): reuse the LDM producer table across dict frames#440
Conversation
On the reused-encoder compress-dict path, reset built a fresh LdmProducer every frame, re-allocating its hash table (large at btultra2). The producer is designed for reuse (clear() re-zeros without allocating); reuse the existing allocation when the derived LDM params are unchanged, matching upstream zstd's ldmState_t lifecycle. clear() keeps the table correct for the new frame.
The dictionary bench looped [3, 19] while the non-dict bench covers [1, 3, 19, 22], so levels 1 and 22 had no dict coverage. Align to LEVELS; verified L1/L22 dict round-trip on the wasm build.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR makes two changes: the dictionary benchmark in ChangesDictionary LDM reuse and benchmark coverage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
| Filename | Overview |
|---|---|
| zstd/src/encoding/match_generator.rs | Restructures the LDM producer wiring block to reuse the existing allocation when derived params are unchanged, avoiding per-frame re-allocation of the large LDM hash table on the reused-encoder dict path. |
| zstd-wasm/bench/bench.mjs | Aligns the dict bench loop variable from a hardcoded [3, 19] to the shared LEVELS constant so levels 1 and 22 receive dict-compress/decompress coverage. |
Comments Outside Diff (1)
-
zstd/src/encoding/match_generator.rs, line 2635-2641 (link)The surrounding comment still says "installing here gives the new frame a fresh producer," but the new behaviour may reuse the existing cleared allocation rather than always installing a freshly-allocated one. The semantic outcome is the same (a correctly initialised producer), but the comment is slightly misleading after this change.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "test(wasm-bench): run dict compress/deco..." | Re-trigger Greptile
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Two compress-dict / LDM follow-ups on the reused-encoder path (the CoordiNode
per-label-dictionary shape):
Reuse the LDM producer table across frames. On the reused-encoder
compress-dict path,
resetbuilt a freshLdmProducerevery frame,re-allocating its hash table (large at btultra2), while upstream zstd reuses
its
ldmState_t. Reuse the existing allocation when the derived LDM paramsare unchanged (
clear()re-zeros without allocating; only a params change orthe first frame builds a new one).
Run the wasm dict bench over all benched levels. The wasm dictionary
bench looped
[3, 19]while the non-dict bench covers[1, 3, 19, 22], solevels 1 and 22 had no dict coverage. Aligned to
LEVELS.Impact
compress-dict/level_22_btultra2_ldmtiming: −3.84% (criterion, i9;"Performance has improved", 31.66 → 30.45 µs vs base). Byte-identical output.
L1/L22 dict round-trip on the wasm build (L22 gives the best ratio).
Testing
cargo nextest run -p structured-zstd --features "hash dict_builder"— 823/823pass, including the dict-primed byte-identity and reused-encoder tests.
Summary by CodeRabbit
Tests
Refactor