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
- links to