liuzqt commented on code in PR #38064:
URL: https://github.com/apache/spark/pull/38064#discussion_r1001073725
##########
core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala:
##########
@@ -84,6 +91,57 @@ private[spark] class ChunkedByteBuffer(var chunks:
Array[ByteBuffer]) {
}
}
+ /**
+ * write to ObjectOutput with zero copy if possible
+ */
+ override def writeExternal(out: ObjectOutput): Unit = {
+ // we want to keep the chunks layout
+ out.writeInt(chunks.length)
+ val chunksCopy = getChunks()
+ chunksCopy.foreach(buffer => out.writeInt(buffer.limit()))
+ var buffer: Array[Byte] = null
+ val bufferLen = ChunkedByteBuffer.estimateBufferChunkSize(size)
+
+ chunksCopy.foreach { chunk => {
+ if (chunk.hasArray) {
+ // zero copy if the bytebuffer is backed by bytes array
+ out.write(chunk.array(), chunk.arrayOffset(), chunk.limit())
Review Comment:
I think the `array()` will returns the reference of the byte array that
backs this buffer, which should not incur extra copy
--
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]