Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-9149

Avoid temp byte array creation when use ByteBufferSerializer

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 2.3.0
    • None
    • clients

    Description

      Code in ByteBufferSerializer#serialize like this

      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;
      }
      

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              javaman_chen chenxu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: