pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rdhabalia commented on a change in pull request #882: Use thread local to allocate temp byte[] instead of allocator
Date Thu, 01 Jan 1970 00:00:00 GMT
rdhabalia commented on a change in pull request #882: Use thread local to allocate temp byte[]
instead of allocator
URL: https://github.com/apache/incubator-pulsar/pull/882#discussion_r148908137
 
 

 ##########
 File path: pulsar-common/src/main/java/org/apache/pulsar/common/util/protobuf/ByteBufCodedInputStream.java
 ##########
 @@ -145,20 +144,22 @@ public void readMessage(final ByteBufMessageBuilder builder, final
ExtensionRegi
         buf.writerIndex(writerIdx);
     }
 
+    private static final FastThreadLocal<byte[]> localByteArray = new FastThreadLocal<>();
+
     /** Read a {@code bytes} field value from the stream. */
     public ByteString readBytes() throws IOException {
         final int size = readRawVarint32();
         if (size == 0) {
             return ByteString.EMPTY;
         } else {
-            RecyclableHeapByteBuf heapBuf = RecyclableHeapByteBuf.get();
-            if (size > heapBuf.writableBytes()) {
-                heapBuf.capacity(size);
+            byte[] localBuf = localByteArray.get();
+            if (localBuf == null || localBuf.length < size) {
+                localBuf = new byte[Math.max(size, 1024)];
 
 Review comment:
   sure.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message