perf: keep shuffle block decompressors from one block to the next #7354
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 431 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7354"
general
weight: 0.35
comphead
Reading a native shuffle block built a new decompressor for every block: zstd allocated a decompression context and window buffers, lz4_flex allocated block-sized input and output buffers as it read the frame, and snap allocated and zero-filled about 140 KiB up front. For the small blocks a reduce task reads by the thousand, that setup was a large share of the decode (#7067, step one).
The decompressors now live in the reader's per-thread state next to the schema cache. The zstd context is kept and reset per frame, as the writer already does with its compression context, and dropped when it outgrows the writer's 8 MiB cap. The lz4_flex and snap decoders own their reader, so a
BlockInputlends them the block for one decode through aLoanguard that revokes the loan, and discards the decoder if the decode did not finish, so a broken frame cannot carry into the next block. lz4_flex sizes its buffers to the frame's block size and asserts they keep it, so one lz4 decoder is kept per block size (64 KiB to 4 MiB, about 11 MiB at most); frames of any other layout get a decoder for that block only. snap only checks for the stream identifier on a decoder's first chunk, so the reader checks it itself to keep the same strictness.shuffle_readerbench, decode_block, Apple M3, median of before -> after:| block | lz4 | zstd | snappy |
|------------------|--------------------|--------------------|---------------------|
| 5 col, 64 rows | 2.24 -> 1.99 µs | 4.69 -> 4.37 µs | 4.13 -> 2.73 µs |
| 5 col, 512 rows | 6.13 -> 5.93 µs | 11.90 -> 11.56 µs | 14.15 -> 12.49 µs |
| 50 col, 64 rows | 12.44 -> 12.05 µs | 12.01 -> 11.66 µs | 19.98 -> 18.30 µs |
| 50 col, 8192 rows| 976 -> 956 µs | 328 -> 328 µs | 2.72 -> 2.64 ms |
The uncompressed path is unchanged within noise. The bench now covers zstd and snappy as well as none and lz4.
Which issue does this PR close?
It addresses the first step mentioned in #7067 but does not close it completely.
How are these changes tested?
New tests in
ipc.rs:decompressors_are_built_once_per_thread: one decoder per codec (two for lz4, one per blocksize) across changes of codec, schema and validation.
failed_decode_does_not_poison_the_next_block: a block truncated inside the compressedstream, early and late, fails and the next valid block of that codec decodes; lz4 and snappy
decoders are replaced, the zstd context is reset in place.
snappy_block_without_stream_identifier_is_rejected_warm.lz4_decoders_are_kept_per_block_size_and_not_for_other_layouts: 64 KiB and 4 MiB frameskeep their own decoder, a linked frame's decoder is not kept, plus the header parse itself.
warm_compressed_decode_allocates_no_more_than_an_uncompressed_one: with the decoders warm,a compressed block allocates no more than the same block uncompressed, for a 3-row and an
8192-row batch and all three codecs, using the crate's counting allocator.
The existing reader tests (truncation, trailing data, lz4 end mark, validation, schema cache)
all still pass; all 201 tests of the shuffle crate pass.
cargo clippy --all-targetsand-D warnings
cargo check --workspace --all-targetspass.decompress.rsalso has unit tests for theBlockInputreader, theLoanguard's keep/discard rules, and the lz4 frame-header parse.