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

Client producer use faster ByteUtils sizeOfXxx algorithm

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.2.0
    • clients, producer
    • None

    Description

      Kafka Java client producer path uses `tryAppend()` requires an estimated size. The sizeOf algorithm currently uses an iterative while loop which can be improved.

      On real system this reduces the producer path CPU by 4%. JMH benchmarking shows the algorithm is approx 3x faster (90 op/ms -> 290op/ms).

      Specifically, we can use a prepared table with the following lookup which relies on JVM intrinsic for fast performance, and also avoids any branching:.

      int leadingZeros = Integer.numberOfLeadingZeros(value);
      return LEADING_ZEROS_TO_U_VARINT_SIZE[leadingZeros];

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jasonkoch Jason Koch
              Ismael Juma Ismael Juma
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: