andygrove opened a new issue, #7064: URL: https://github.com/apache/datafusion-comet/issues/7064
### What is the problem the feature request solves? #6805 removed `Channels.newChannel` from the shuffle readers, and #7016 replaces it on the broadcast and collect read paths. Three write paths still go through it: - `Utils.serializeBatches` ([Utils.scala#L276](https://github.com/apache/datafusion-comet/blob/3a4a15940983e4bb9a9a74c816ee51e2cf6d9e17/spark/src/main/scala/org/apache/spark/sql/comet/util/Utils.scala#L276)), which serializes every broadcast build side and, through `getByteArrayRdd`, every Comet `collect()` and `take()`; - the re-serialization in `Utils.coalesceBroadcastBatches` ([Utils.scala#L450](https://github.com/apache/datafusion-comet/blob/3a4a15940983e4bb9a9a74c816ee51e2cf6d9e17/spark/src/main/scala/org/apache/spark/sql/comet/util/Utils.scala#L450)); - the cache serializer's batch writer ([CachedBatchIpc.scala#L239](https://github.com/apache/datafusion-comet/blob/3a4a15940983e4bb9a9a74c816ee51e2cf6d9e17/spark/src/main/scala/org/apache/spark/sql/comet/execution/arrow/CachedBatchIpc.scala#L239)). For an `OutputStream`, the JDK returns a channel that copies at most 8 KiB per write into a heap array before handing it to the stream. Arrow's `WriteChannel` hands it each buffer of the batch as a `ByteBuffer`, usually a direct one. So every serialized byte is copied once more than it needs to be, through a channel that takes a lock and does an interruptible begin/end per 8 KiB piece. I haven't measured these paths. For comparison, the read-side change in #7016 measured about 2.5% of a broadcast decode. The read side of `CachedBatchIpc` uses the channel only for the message header and copies the body directly, so it is fine as is. ### Describe the potential solution A small `WritableByteChannel` that writes a `ByteBuffer` to the stream in larger pieces through one reused array, or straight from the buffer's backing array when it has one. That is the write-side counterpart of #7016's `InputStreamChannel`. ### Additional context `CometArrowPythonRunnerBase` also wraps its socket stream in `Channels.newChannel`, but Spark's own `ArrowPythonRunner` does the same, so that one is parity with Spark. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
