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.
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 cf4ad91..f8dd8f4 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 @@
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 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();