perf: reuse LZ4 frame encoder state across shuffle blocks #7606
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 288 lines diff across 3 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
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.339
Real PR Conversation Timeline
1 comments
"Review active on #7606"
general
weight: 0.35
sunchao
Which issue does this PR close?
Part of #6916.
Rationale for this change
compress_ipc_streambuilds a newlz4_flexFrameEncoderfor every shuffle block. That is a zeroed 16 KiB hash table, a 64 KiB input buffer and a 72,109 byte output buffer per block, plus a copy of the IPC stream into the input buffer. Keeping one lz4_flexFrameEncoder<Vec<u8>>and copying each frame out also reuses that state, but it measured no faster than main on 8192-row blocks.What changes are included in this PR?
lz4_frame.rs: a small LZ4 frame writer on top oflz4_flex::block::compress_into_with_tablethat keeps its buffers and hash table across blocks. It writes standard LZ4 frames with independent 64 KiB blocks, the same layout remote shuffle already used.ShuffleCodecContextholds the encoder.release_zstdis renamed torelease_workspacesand drops both.The block format doesn’t change, and all readers are native, so old and new writers and readers can be mixed.
How are these changes tested?
FrameEncoder, and multi-block frames round trip throughFrameDecoderfor several sizes and write patterns. Another test covers releasing the encoder on the remote path.lz4CLI (1.9.4) decodes frames taken from real shuffle blocks.cargo test -p datafusion-comet-shufflepasses, and clippy is clean.Benchmarks (
shuffle_writer, Threadripper PRO 5975WX, 5 alternating rounds, median):| Benchmark | main | this PR | change |
|---|---:|---:|---:|
| write encoded, 8192 rows, LZ4 | 279.5 µs | 213.2 µs | -23.7% |
| ipc_context mixed/8192/LZ4/reused | 282.3 µs | 214.4 µs | -24.1% |
| ipc_context flat/8192/LZ4/reused | 226.1 µs | 191.0 µs | -15.5% |
| end to end, 2000 partitions, LZ4 (cases from #7199) | 12.39 ms | 11.52 ms | -7.0% |
| end to end, 8000 partitions, LZ4 (cases from #7199) | 23.69 ms | 22.37 ms | -5.6% |
At 200 partitions, and for 128-row blocks with a fresh context (what remote shuffle does), the change is within noise. Allocations per 128-row LZ4 block drop from 171,325 bytes to 17,296, the same as no compression.