[ https://issues.apache.org/jira/browse/KAFKA-9149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16968207#comment-16968207 ]
ASF GitHub Bot commented on KAFKA-9149: --------------------------------------- chenxu14 commented on pull request #7656: KAFKA-9149 Avoid temp byte array creation when use ByteBufferSerializer URL: https://github.com/apache/kafka/pull/7656 Avoid temp byte array creation when use ByteBufferSerializer ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Avoid temp byte array creation when use ByteBufferSerializer > ------------------------------------------------------------ > > Key: KAFKA-9149 > URL: https://issues.apache.org/jira/browse/KAFKA-9149 > Project: Kafka > Issue Type: Improvement > Components: clients > Reporter: chenxu > Priority: Major > > Code in ByteBufferSerializer#serialize like this > {code:java} > public byte[] serialize(String topic, ByteBuffer data) { > if (data == null) > return null; > data.rewind(); > if (data.hasArray()) { > byte[] arr = data.array(); > if (data.arrayOffset() == 0 && arr.length == data.remaining()) { > return arr; > } > } > byte[] ret = new byte[data.remaining()]; > data.get(ret, 0, ret.length); > data.rewind(); > return ret; > } > {code} > Temp byte array will be created when use with DirectByteBuffer, how about > declare a method such as serialize2Buffer and return the ByteBuffer directly > ? This can improve GC a lot in KafkaProducer. -- This message was sent by Atlassian Jira (v8.3.4#803005)