← Back to Pull requests

perf: keep shuffle block decompressors from one block to the next #7354

Open
unknown opened this pull request with 431 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 30, 2026 20:52 UTC
Author

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 BlockInput lends them the block for one decode through a Loan guard 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_reader bench, 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 block

  • size) across changes of codec, schema and validation.
  • failed_decode_does_not_poison_the_next_block: a block truncated inside the compressed

  • stream, 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 frames

  • keep 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-targets
    -D warnings
    and cargo check --workspace --all-targets pass.

    decompress.rs also has unit tests for the BlockInput reader, the Loan guard's keep/discard rules, and the lz4 frame-header parse.

    Diff: 431 lines (+323 / -108) across 5 files Reviewer: comphead Review duration: 7373m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.1% · Safe to merge
    24.1%