You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/25 04:30:43 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #17822: [improve][java-client]Add init capactiy for messages in BatchMessageContainerImpl

AnonHxy commented on code in PR #17822:
URL: https://github.com/apache/pulsar/pull/17822#discussion_r979352513


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageContainerImpl.java:
##########
@@ -168,12 +168,13 @@ private ByteBuf getCompressedBatchMetadataAndPayload() {
         // Update the current max batch size using the uncompressed size, which is what we need in any case to
         // accumulate the batch content
         maxBatchSize = Math.max(maxBatchSize, uncompressedSize);
+        maxMessagesNum = Math.max(maxMessagesNum, numMessagesInBatch);
         return compressedPayload;
     }
 
     @Override
     public void clear() {
-        messages = new ArrayList<>();
+        messages = new ArrayList<>(maxMessagesNum);

Review Comment:
   If using `message.clear()`, there will be some cpu overhead I think.  We must check if `messages.size == maxMessageNum`, and the clear() method will loop all the elements in the arrayList:
   ```
    public void clear() {
           modCount++;
           final Object[] es = elementData;
           for (int to = size, i = size = 0; i < to; i++)
               es[i] = null;
       }
   ```



-- 
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-unsubscribe@pulsar.apache.org

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