wang-jiahua opened a new issue, #10464:
URL: https://github.com/apache/rocketmq/issues/10464

   ### Motivation
   
   JFR profiling on the broker send path reveals two per-message allocation 
issues in `Message.java`:
   
   1. **`getProperty(String)`** — when `properties == null` (common for freshly 
constructed messages before tags/keys are set), the current code creates a `new 
HashMap<>()` as a side-effect of a read-only call, then immediately discards 
it. This adds ~one empty HashMap allocation per send on the producer side.
   
   2. **`getPriority()`** — delegates to 
`NumberUtils.toInt(getProperty(PROPERTY_PRIORITY), -1)`. When PRIORITY is unset 
(the vast majority of messages), `getProperty` returns `null`, and 
`NumberUtils.toInt(null, ...)` internally calls `Integer.parseInt(null)` which 
throws and catches a `NumberFormatException` on every invocation. JFR 
`jdk.JavaExceptionThrow` shows ~16,000 NFE/min from this path.
   
   ### Proposed Changes
   
   - `getProperty()`: return `null` immediately when `properties == null` 
instead of creating an empty HashMap.
   - `getPriority()`: add a null/empty fast-path before calling 
`NumberUtils.toInt()` to skip the NFE throw+catch.
   
   ### Impact
   
   - Eliminates one per-send empty HashMap allocation on the producer side.
   - Eliminates ~16,000 NFE exceptions/min under benchmark load, reducing 
stack-trace allocation and CPU overhead.


-- 
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]

Reply via email to