You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Jason Koch (Jira)" <ji...@apache.org> on 2022/01/30 18:56:00 UTC
[jira] [Updated] (KAFKA-13629) Client producer use faster ByteUtils sizeOfXxx algorithm
[ https://issues.apache.org/jira/browse/KAFKA-13629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jason Koch updated KAFKA-13629:
-------------------------------
Summary: Client producer use faster ByteUtils sizeOfXxx algorithm (was: Use faster ByteUtils sizeOfXxx algorithm)
> Client producer use faster ByteUtils sizeOfXxx algorithm
> --------------------------------------------------------
>
> Key: KAFKA-13629
> URL: https://issues.apache.org/jira/browse/KAFKA-13629
> Project: Kafka
> Issue Type: Improvement
> Components: clients, producer
> Reporter: Jason Koch
> Priority: Minor
>
> Kafka Java client producer path uses `tryAppend()` requires an estimated size. The sizeOf algorithm currently uses an [iterative while loop|https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/utils/ByteUtils.java#L394-L401] 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];}}
> --
--
This message was sent by Atlassian Jira
(v8.20.1#820001)