LiangliangSui commented on code in PR #1434:
URL: https://github.com/apache/incubator-fury/pull/1434#discussion_r1554983464


##########
java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java:
##########
@@ -1233,49 +1233,9 @@ public int readVarInt() {
    * to avoid using two memory operations.
    */
   public int unsafeWritePositiveVarInt(int v) {
-    // The encoding algorithm are based on kryo UnsafeMemoryOutput.writeVarInt
-    // varint are written using little endian byte order.
-    // This version should have better performance since it remove an index 
update.
-    long value = v;
-    final int writerIndex = this.writerIndex;
-    long varInt = (value & 0x7F);
-    value >>>= 7;
-    if (value == 0) {
-      UNSAFE.putByte(heapMemory, address + writerIndex, (byte) varInt);
-      this.writerIndex = writerIndex + 1;
-      return 1;
-    }
-    // bit 8 `set` indicates have next data bytes.
-    varInt |= 0x80;
-    varInt |= ((value & 0x7F) << 8);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 2;
-      return 2;
-    }
-    varInt |= (0x80 << 8);
-    varInt |= ((value & 0x7F) << 16);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 3;
-      return 3;
-    }
-    varInt |= (0x80 << 16);
-    varInt |= ((value & 0x7F) << 24);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 4;
-      return 4;
-    }
-    varInt |= (0x80L << 24);
-    varInt |= ((value & 0x7F) << 32);
-    varInt &= 0xFFFFFFFFFL;
-    unsafePutLong(writerIndex, varInt);
-    this.writerIndex = writerIndex + 5;
-    return 5;
+    int varintBytes = unsafePutPositiveVarInt(writerIndex, v);

Review Comment:
   with this pr
   ```
   Benchmark                                         (bufferType)   
(objectType)  (references)   Mode  Cnt        Score        Error  Units
   UserTypeSerializeSuite.fury_serialize_compatible         array  
MEDIA_CONTENT         false  thrpt    9  4587893.508 ±  42116.854  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible         array  
MEDIA_CONTENT          true  thrpt    9  3177202.586 ±  14736.954  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible  directBuffer  
MEDIA_CONTENT         false  thrpt    9  4562769.304 ± 340601.623  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible  directBuffer  
MEDIA_CONTENT          true  thrpt    9  3079333.765 ±  61135.629  ops/s
   ```
   
   before this pr
   ```
   Benchmark                                         (bufferType)   
(objectType)  (references)   Mode  Cnt        Score        Error  Units
   UserTypeSerializeSuite.fury_serialize_compatible         array  
MEDIA_CONTENT         false  thrpt    9  4602232.298 ± 107310.721  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible         array  
MEDIA_CONTENT          true  thrpt    9  3141775.420 ±  59485.987  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible  directBuffer  
MEDIA_CONTENT         false  thrpt    9  4755918.332 ±  65920.575  ops/s
   UserTypeSerializeSuite.fury_serialize_compatible  directBuffer  
MEDIA_CONTENT          true  thrpt    9  3118601.861 ± 140368.292  ops/s
   ```
   
   I run fury benchmark for MediaContent object, there should be no degradation 
in performance, within the error range.



-- 
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: commits-unsubscr...@fury.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org
For additional commands, e-mail: commits-h...@fury.apache.org

Reply via email to