datafusion-ballista icon indicating copy to clipboard operation
datafusion-ballista copied to clipboard

Coalesce small batches in the passthrough shuffle writer

Open NoahKusaba opened this issue 2 months ago • 0 comments

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

The passthrough shuffle writer (ShuffleWriterExec) writes every batch it receives from its child as its own Arrow IPC message, with its own compression frame (utils::write_stream_to_disk). Unlike SortShuffleWriterExec, which rebuilds batches at batch_size when it interleaves rows into buckets, the passthrough writer keeps whatever batch sizes the child produces.

After a selective FilterExec, or a RepartitionExec that spreads rows across many outputs, those batches can be only a few hundred rows. That makes shuffle files bigger, adds a compression frame for every tiny batch, and gives downstream readers more batches to decode.

Describe the solution you'd like

Coalesce batches up to the session batch_size before writing them, using arrow's BatchCoalescer. Batches larger than batch_size / 2 should be written as-is when nothing is buffered, so large batches aren't copied. DataFusion's CoalesceBatchesExec uses the same setting (LimitedBatchCoalescer::new).

Describe alternatives you've considered

Inserting a CoalesceBatchesExec under the writer at planning time. Coalescing inside the writer keeps the work on the writer's blocking thread and doesn't change the stage plan.

Additional context

ShuffleReaderExec already coalesces on the read side with the same batch_size. Doing it at write time also cuts the number of IPC messages and compression frames stored on disk and sent over the network.

NoahKusaba avatar Oct 01 '26 19:10 NoahKusaba