You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2022/08/09 22:51:58 UTC

[qpid-protonj2] branch main updated: PROTON-2591 Provide a non-default allocation size for message buffers

This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 22ac0613 PROTON-2591 Provide a non-default allocation size for message buffers
22ac0613 is described below

commit 22ac0613f24c3818b8ccc86c8cb7be4eb79e4302
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Tue Aug 9 18:51:41 2022 -0400

    PROTON-2591 Provide a non-default allocation size for message buffers
    
    Provide a larger than default size for initial buffer allocation for
    encoding messages (256 bytes) which avoids a rapid buffer reallocation
    and copy for most small outgoing messages.
---
 .../org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
index cf4ad91f..f8dd8f45 100644
--- a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
+++ b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
@@ -54,6 +54,8 @@ public abstract class ClientMessageSupport {
     private static final Encoder DEFAULT_ENCODER = CodecFactory.getDefaultEncoder();
     private static final Decoder DEFAULT_DECODER = CodecFactory.getDefaultDecoder();
 
+    private static final int DEFAULT_BUFFER_ALLOCATION = 256;
+
     private static final ThreadLocal<EncoderState> THREAD_LOCAL_ENCODER_STATE =
         ThreadLocal.withInitial(() -> DEFAULT_ENCODER.newEncoderState());
     private static final ThreadLocal<DecoderState> THREAD_LOCAL_DECODER_STATE =
@@ -105,7 +107,7 @@ public abstract class ClientMessageSupport {
     }
 
     public static ProtonBuffer encodeMessage(Encoder encoder, EncoderState encoderState, ProtonBufferAllocator allocator, AdvancedMessage<?> message, Map<String, Object> deliveryAnnotations) throws ClientException {
-        ProtonBuffer buffer = allocator.allocate();
+        ProtonBuffer buffer = allocator.allocate(DEFAULT_BUFFER_ALLOCATION);
 
         Header header = message.header();
         MessageAnnotations messageAnnotations = message.annotations();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org