You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "chenxu (Jira)" <ji...@apache.org> on 2019/11/06 07:01:00 UTC
[jira] [Created] (KAFKA-9149) Avoid temp byte array creation when
use ByteBufferSerializer
chenxu created KAFKA-9149:
-----------------------------
Summary: 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
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)