jbonofre commented on code in PR #1851:
URL: https://github.com/apache/activemq/pull/1851#discussion_r3005734140


##########
activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java:
##########
@@ -182,15 +181,22 @@ public void clearBody() throws JMSException {
 
     @Override
     public int getSize() {
+        int minimumMessageSize = getMinimumMessageSize();
+        ByteSequence content = this.content;
         String text = this.text;
-        if (size == 0 && content == null && text != null) {
-            size = getMinimumMessageSize();
-            if (marshalledProperties != null) {
-                size += marshalledProperties.getLength();
-            }
+
+        size = minimumMessageSize;
+        if (marshalledProperties != null) {
+            size += marshalledProperties.getLength();
+        }
+        if (content != null) {
+            size += content.getLength();
+        }
+        if (text != null) {
             size += text.length() * 2;
         }
-        return super.getSize();
+
+        return size;

Review Comment:
   You always recalculates size from scratch, while `super.getSize()` (from 
`Message`)  only recalculates when `size < minimumMessageSize || size == 0`. 
   Here, you directly set `this.size` and returns it, completely bypassing 
`super.getSize()`.
   
   This basically means:
   * The size is recalculated on every single call (potentially performance 
regression)
   * When both `text` and `content` are present (which is now always the case 
after `beforeMarshall`), it double-counts the payload (the text characters and 
their serialized byte form). This inflates memory tracking and could cause 
premature flow control or producer blocking.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to