forked from KillingSpark/zstd-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
perf(encode): cut dict-compress per-frame overhead; shrink wasm payload 18% #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d77a0bd
perf(encode): reuse rollback entropy snapshot buffers per block
polaz 1287a27
perf(encode): feed slice inputs to owned block loop without zero-fill
polaz 1b5279c
perf(encode): epoch-bias Fast table reset for dict-attach frames
polaz f2cd65b
perf(encode): fold optimal-plan profile dispatch on strategy consts
polaz 53e8305
test(bench): decode_loop_dict profiling example + dict payload dump
polaz 01aa801
test(bench): dump scenario input bytes alongside the trained dict
polaz 737909e
perf(encode): donor pre-build incompressibility gate for literals
polaz 4b58210
docs(encode): document why compress() source is not restored on unwind
polaz 6233d0f
perf(encode): run the lazy band (L6-12) on the row match finder
polaz 773b09a
perf(encode): iterate row tag-mask hits instead of scanning every slot
polaz 6992e67
fix(bench): non-fatal dump writes; validate decode length in decode_l…
polaz bfd4950
perf(encode): 4-byte gate before repcode common_prefix_len
polaz 6b5773c
perf(encode): prefetch the upcoming row in the lazy scan loop
polaz ba30e78
perf(encode): row hash ring cache feeding probe and post-miss insert
polaz d83ba61
fix(encode): keep btlazy2 off the Row finder; donor hashLog cap for r…
polaz bda8010
Revert "perf(encode): row hash ring cache feeding probe and post-miss…
polaz fc1cff3
Revert "perf(encode): prefetch the upcoming row in the lazy scan loop"
polaz 4874f0b
fix(encode): let donor row hash widths reach the backend; btlazy2 par…
polaz ee9bc09
fix(encode): key row snapshots on the applied hash width, keep 20-bit…
polaz 985ca24
fix(bench): checksum parity for the FFI dictionary arms
polaz d044bc1
fix(encode)!: default content checksum off (upstream library parity)
polaz 5bf5a03
docs(encode): align checksum-default docs and bench config ordering
polaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //! Standalone decode-loop binary for CLEAN perf-record profiles of the | ||
| //! dictionary DECODE hot path. Mirrors the `decompress-dict/...` bench arm | ||
| //! exactly: parse the dictionary into a [`DictionaryHandle`] ONCE, build one | ||
| //! reused [`FrameDecoder`], then loop `decode_all_with_dict_handle` over a | ||
| //! fixed `.zst` payload into a preallocated output buffer — no criterion, no | ||
| //! FFI, no training; samples land purely on the per-frame decode path. | ||
| //! | ||
| //! The payload should be the FFI dict-encoded frame the bench measures; dump | ||
| //! both files from a bench run via | ||
| //! `STRUCTURED_ZSTD_DUMP_DICT_DIR=<dir> cargo bench --bench compare_ffi ...` | ||
| //! (`<scenario>.dict` + `<scenario>.<level>.zst`). | ||
| //! | ||
| //! Build: `cargo build --profile flamegraph -p structured-zstd | ||
| //! --example decode_loop_dict` | ||
| //! Run: `decode_loop_dict <iters> <payload.zst> <dict> <expected_len>` | ||
|
|
||
| use std::env; | ||
|
|
||
| use structured_zstd::decoding::{DictionaryHandle, FrameDecoder}; | ||
|
|
||
| fn main() { | ||
| let args: Vec<String> = env::args().collect(); | ||
| let iters: u32 = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(500_000); | ||
| let payload_path = args | ||
| .get(2) | ||
| .map(String::as_str) | ||
| .unwrap_or("/tmp/szstd-dicts/small-4k-log-lines.level_2_fast.zst"); | ||
| let dict_path = args | ||
| .get(3) | ||
| .map(String::as_str) | ||
| .unwrap_or("/tmp/szstd-dicts/small-4k-log-lines.dict"); | ||
| let expected_len: usize = args.get(4).and_then(|s| s.parse().ok()).unwrap_or(4096); | ||
|
|
||
| let payload = std::fs::read(payload_path).expect("read payload file"); | ||
| let dict = std::fs::read(dict_path).expect("read dict file"); | ||
| let handle = DictionaryHandle::decode_dict(dict.as_slice()).expect("parse dictionary"); | ||
|
|
||
| let mut decoder = FrameDecoder::new(); | ||
| let mut output = vec![0u8; expected_len]; | ||
| let mut sink: usize = 0; | ||
| for _ in 0..iters { | ||
| let n = decoder | ||
| .decode_all_with_dict_handle(payload.as_slice(), output.as_mut_slice(), &handle) | ||
| .expect("dict decode should succeed"); | ||
| // A short decode means the (payload, dict, expected_len) triple is | ||
| // mismatched — fail loudly instead of profiling the wrong workload. | ||
| assert_eq!(n, expected_len, "decoded length mismatch"); | ||
| sink = sink.wrapping_add(n); | ||
| core::hint::black_box(&output[..n]); | ||
| } | ||
|
|
||
| eprintln!( | ||
| "decoded {} bytes x {} iters (payload {} bytes, dict {} bytes); out-sum={}", | ||
| expected_len, | ||
| iters, | ||
| payload.len(), | ||
| dict.len(), | ||
| sink | ||
| ); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //! Print donor cParams for levels 1..=22 at a given source size. | ||
| //! Companion to `donor_cparams_check` for sweeping a whole level band. | ||
| //! | ||
| //! Run: `cargo run --release -p structured-zstd --example donor_cparams_range | ||
| //! --features dict_builder -- [src_size]` (0 / omitted = unbounded). | ||
| use zstd::zstd_safe::zstd_sys; | ||
|
|
||
| fn main() { | ||
| let src_size: u64 = std::env::args() | ||
| .nth(1) | ||
| .and_then(|s| s.parse().ok()) | ||
| .unwrap_or(0); | ||
| for level in 1..=22i32 { | ||
| // SAFETY: standard libzstd query. | ||
| let cp = unsafe { zstd_sys::ZSTD_getCParams(level, src_size, 0) }; | ||
| println!( | ||
| "L{level}: wlog={} clog={} hlog={} slog={} mml={} tlen={} strat={}", | ||
| cp.windowLog, | ||
| cp.chainLog, | ||
| cp.hashLog, | ||
| cp.searchLog, | ||
| cp.minMatch, | ||
| cp.targetLength, | ||
| cp.strategy as u32 | ||
| ); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.