apache / apache/datafusion-comet

Reuse the decoded schema across shuffle blocks instead of re-parsing it per block

Open
#5,792 1 comment 0 reactions 0 assignees View on GitHub
requires-triage
Dominant language
Scala
Stars
1.3k
Forks
373
Avg merge
2d 4h
Merged PRs (30d)
198

Description

### What is the problem the feature request solves?

Every native shuffle block is a self-contained Arrow IPC stream: schema message, dictionary messages, record batch message, end-of-stream marker. On the read side `read_single_batch` builds a fresh `StreamReader` for each block, so the schema flatbuffer is parsed once per block, even though every block in a shuffle carries the same schema and the reducer already knows that schema from the plan protobuf (`ShuffleScanExec` builds it from `data_types`).

The write side already avoids the mirror image of this cost. `ShuffleBlockWriter` encodes the schema flatbuffer once in `try_new` and writes those pre-encoded bytes verbatim at the start of every block (`SchemaEncoding::Precoded`) rather than re-serializing per block. The reader has no equivalent.

Blocks per reduce task scale with the number of mappers times the number of blocks each mapper wrote for that partition, and a mapper writes at least one block per spill round, so this grows with both cluster width and memory pressure.

### Describe the potential solution

The cost to remove is the flatbuffer parse and `StreamReader` setup, not I/O: the schema message sits inside the compressed stream and is decompressed either way. A reader that caches the parsed schema and skips re-parsing when a block's decompressed schema message matches the cached bytes would keep the current block format intact.

Dropping the schema message from the format outright would be cheaper still, since the reducer does not need it, but that changes the wire format and would have to account for the RSS path and for the dictionary-schema fallback, which does not use `Precoded`.

Unmeasured so far. Worth a read-side benchmark at a high mapper count before acting.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at read_single_batch and compare its per-block StreamReader setup with ShuffleBlockWriter's try_new and SchemaEncoding::Precoded path. Trace how ShuffleScanExec obtains data_types, and account for the RSS path and dictionary-schema fallback. Benchmark reads at high mapper counts; done means repeated schema parsing is avoided while the current block format remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, scala
Domain
distributed-systems, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.