Skip to content

perf(core): zero-copy block receive on the remote fetch path - #2312

Merged
Dandandan merged 1 commit into
apache:mainfrom
Dandandan:perf/zero-copy-block-receive
Aug 16, 2026
Merged

perf(core): zero-copy block receive on the remote fetch path#2312
Dandandan merged 1 commit into
apache:mainfrom
Dandandan:perf/zero-copy-block-receive

Conversation

@Dandandan

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

N/A

Rationale for this change

BlockDataStream copied every incoming transport block into a freshly allocated buffer, even when nothing was pending:

self.state_buffer = Self::combine_buffers(&self.state_buffer, &Buffer::from(blob))

Two facts make that copy avoidable in the steady state:

  • Buffer::from(bytes::Bytes) adopts the transport allocation rather than copying it.
  • StreamDecoder::decode loops while !buffer.is_empty(), and every non-error early return is Ok(Some(batch)). So whenever it returns Ok(None) — the only condition under which poll_next pulls another block — state_buffer has been fully drained.

So on the hot path the incoming block can simply be adopted. Concatenation is only needed for a partial message straddling a block boundary, which is what the schema-accumulation loop in try_new relies on (try_schema_from_ipc_buffer peeks without consuming, so a partial header stays pending there).

What changes are included in this PR?

combine_buffers is replaced by append_block, which adopts the incoming block when nothing is pending and otherwise falls back to the existing concatenating path. Both call sites — the schema loop in try_new and extend_bytes — move to it.

This is on by default for all remote shuffle reads; there is no new configuration.

Are these changes tested?

Yes. The existing BlockDataStream tests cover both paths and still pass — should_process_chunked (2-byte blocks) drives the concatenating path in the schema loop, and should_process_single_message covers whole-block adoption.

Added should_process_multi_block_payload, which round-trips a payload spanning several whole blocks at 8/64/512-byte block sizes, covering the mixed regime this change targets.

cargo test --package ballista-core --lib client:: — 6 passed, 0 failed. cargo clippy --all-targets --package ballista-core --all-features -- -D warnings and cargo fmt --all -- --check are clean.

Benchmark

65 MiB payload at the server's 8 MiB block size: 69.7 ms → 22.7 ms (−67%). At 1 MiB blocks: 41.8 ms → 34.9 ms (−17%).

Are there any user-facing changes?

No API changes — combine_buffers and append_block are both private. Remote shuffle reads get faster.

🤖 Generated with Claude Code

…taStream

`BlockDataStream` concatenated every incoming block into a freshly
allocated buffer, even when nothing was pending. `Buffer::from(Bytes)`
adopts the transport allocation rather than copying it, and
`StreamDecoder::decode` drains `state_buffer` completely before the
stream asks for another block, so in the steady state the block can be
taken as-is.

Replace `combine_buffers` with `append_block`, which adopts the incoming
block when nothing is pending and falls back to concatenating only for a
partial message straddling a block boundary — the case the schema
accumulation loop in `try_new` relies on.

65 MiB payload at the server's 8 MiB block size: 69.7 ms -> 22.7 ms
(-67%). At 1 MiB blocks: 41.8 ms -> 34.9 ms (-17%).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Dandandan
Dandandan requested a review from milenkovicm August 16, 2026 04:57

@milenkovicm milenkovicm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dandandan makes sense

@Dandandan
Dandandan merged commit f3055a4 into apache:main Aug 16, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants