From 4d27f2e7d7ae2f6ce71a73d3edeb1a866815d043 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Thu, 19 Apr 2018 17:46:26 +0200 Subject: [PATCH] ARTEMIS-1816 OpenWire should avoid ByteArrayOutputStream lazy allocation OpenWireMessageConverter::toAMQMessage on bytes messages is lazy allocating a write buffer with a default size of 1024 even when it won't be used to write anything. It avoid an useless allocation by reducing it to new byte[0]. --- .../protocol/openwire/OpenWireMessageConverter.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java index fd1f7320d5..49d897de58 100644 --- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java +++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java @@ -504,6 +504,15 @@ public final class OpenWireMessageConverter { return md; } + private static final class EagerActiveMQBytesMessage extends ActiveMQBytesMessage { + + EagerActiveMQBytesMessage(int size) { + this.bytesOut = new org.apache.activemq.util.ByteArrayOutputStream(size); + OutputStream os = bytesOut; + this.dataOut = new DataOutputStream(os); + } + } + private static ActiveMQMessage toAMQMessage(MessageReference reference, ICoreMessage coreMessage, WireFormat marshaller, @@ -518,7 +527,7 @@ public final class OpenWireMessageConverter { switch (coreType) { case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE: - amqMsg = new ActiveMQBytesMessage(); + amqMsg = new EagerActiveMQBytesMessage(0); bytes = toAMQMessageBytesType(buffer, isCompressed); break; case org.apache.activemq.artemis.api.core.Message.MAP_TYPE: