Repository navigation
fix: assemble split IPC messages in StreamDecoder at their declared size - #11648
Merged
Merged
Conversation
…ed like StreamReader
Jefffrey
approved these changes
Oct 18, 2026
Contributor
|
thanks @ranflarion |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Rationale for this change
StreamDecoderassembles a message that arrives split across input buffers in a scratchMutableBufferthat starts empty and doubles as the pieces are copied in, and the decoded batch is zero-copy over that buffer, so it keeps between 1x and 2x its body alive. A reader that feeds fixed-size chunks hits this on nearly every message large enough to span one: DataFusion 55 reads spill files back in 128 KiB chunks, and a spilling sort's read-back batches held 2,969 MiB for 2,198 MiB of data.StreamReaderavoids it since #10522 by reading a body intomin(body_length, MAX_PREALLOC_BYTES)up front.What changes are included in this PR?
When the first bytes of a message flatbuffer or body are copied into the empty scratch buffer, the decoder now reserves the declared length, capped at
MAX_PREALLOC_BYTESthe same wayread_body_boundedcaps it. A message up to 64 MiB is therefore allocated once at its size, while an implausible declared length still reserves at most 64 MiB and leaves the decoder waiting for bytes that never arrive. Larger messages keep growing geometrically past the cap, as they do inStreamReader. The path that slices a message straight out of a single input buffer is unchanged.Are these changes tested?
Yes, two tests in
arrow-ipc/src/reader/stream.rs.test_split_body_is_buffered_at_its_declared_sizefeeds a 99,272 byte stream one byte at a time and checks the decoded batch holds no more than the stream: without the change it holds 131,072 bytes.test_implausible_body_length_reserves_a_bounded_bufferdeclares body lengths ofi64::MAXand1 << 50and checks the decoder keeps waiting for the body: reserving the declared length without the cap fails it withMemoryError("invalid allocation layout for requested capacity").In the DataFusion sort from the issue, built against arrow 59.3 with this change, peak native allocation went from 201.8 MiB to 161.0 MiB.
The
arrow-ipcsuite passes (138 library tests, including the two above), along withcargo fmt --all -- --checkandcargo clippy -p arrow-ipc --all-targets --all-features -- -D warnings.Are there any user-facing changes?
No API changes. Batches decoded from split messages hold less memory. No breaking changes.