divijvaidya commented on code in PR #13312:
URL: https://github.com/apache/kafka/pull/13312#discussion_r1120328865


##########
clients/src/main/java/org/apache/kafka/common/utils/ByteUtils.java:
##########
@@ -227,17 +259,62 @@ public static int readVarint(DataInput in) throws 
IOException {
      * @throws IOException              if {@link DataInput} throws {@link 
IOException}
      */
     public static long readVarlong(DataInput in) throws IOException {
-        long value = 0L;
-        int i = 0;
-        long b;
-        while (((b = in.readByte()) & 0x80) != 0) {
-            value |= (b & 0x7f) << i;
-            i += 7;
-            if (i > 63)
-                throw illegalVarlongException(value);
+        long raw = readUnsignedVarlong(in);
+        return (raw >>> 1) ^ -(raw & 1);
+    }
+
+    private static long readUnsignedVarlong(DataInput in) throws IOException {
+        byte tmp = in.readByte();

Review Comment:
   No, I have written this by extending Netty's varint32 implementation to work 
with 64 bits (it's simple loop unrolling, no fancy logic). The heuristics of 
inlining starts becoming unclearer as we increase the size of function, hence, 
we don't see much benefit for 64 bit implementation here. I don't have a strong 
opinion on 64 bit implementation here and would be happy to fall back to exact 
implementation as Protobuf. [1]
   
   
   [1] 
https://github.com/protocolbuffers/protobuf/blob/main/java/core/src/main/java/com/google/protobuf/CodedInputStream.java#L1048



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to