Skip to content

Optimize CometBroadcastHashJoin: use CollectLeft partition mode and cache deserialized broadcast batches #3692

Closed

Description

@andygrove

Summary

CometBroadcastHashJoin has two significant performance bottlenecks:

1. Native side always uses PartitionMode::Partitioned for broadcast joins

In planner.rs:1673, all hash joins are hardcoded to PartitionMode::Partitioned. DataFusion supports PartitionMode::CollectLeft which is specifically designed for broadcast joins — it skips repartitioning and builds the hash table directly from the collected (broadcast) side. The protobuf schema (operator.proto:331-337) also has no field to distinguish broadcast from shuffled joins.

2. Per-task deserialization of broadcast data with no caching

In CometBroadcastExchangeExec.scala:312-315, every task independently deserializes the entire broadcast payload via Utils.decodeBatches(). There is no executor-level caching of deserialized Arrow batches between tasks on the same executor. With N partitions, the same broadcast data is deserialized N times per executor.

Additional context

The broadcast data also goes through a triple serialization cycle:

  • Child output → serialized to ChunkedByteBuffer
  • Broadcast to executors
  • Deserialized per task back to Arrow batches
  • Then fed through JNI/Arrow FFI to native code

Proposed changes

  1. Add an is_broadcast field to the HashJoin protobuf message and use PartitionMode::CollectLeft on the native side for broadcast joins
  2. Cache deserialized broadcast batches at the executor level to avoid re-decoding the same data for every task

Activity

  1. mbutrovich commented on Mar 13, 2026

    @mbutrovich
    Contributor

    Thanks for writing this up, @andygrove! I'm not sure the CollectLeft is going to affect the join execution much since I think it's mostly related to DataFusion's optimizer, but it is more correct to set it, I suppose.

    The second optimization will hopefully be a win though.

  2. mbutrovich commented on Mar 13, 2026

    @mbutrovich
    Contributor

    Also I think issue two only discusses the deserialization issue. There is still the serialization issue of per-partition creating IPC writers, writing a batch, etc. Ideally we want to

    1. only use one IPC writer
    2. (optional) concatenate the batches on the driver side using Arrow Java.
  3. andygrove commented on Mar 14, 2026

    @andygrove
    MemberAuthor

    I had a brief look at this with Claude yesterday, but did not make any meaningful progress. I am going to focus on fixing the remaining native_datafusion failures for now.

  4. mbutrovich commented on Mar 14, 2026

    @mbutrovich
    Contributor

    No worries. I can take a look next week as well. Thanks for chipping away at the native_DataFusion tasks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions