wang-jiahua opened a new pull request, #10469:
URL: https://github.com/apache/rocketmq/pull/10469

   ### Which Issue(s) This PR Fixes
   
   Fixes #10467
   
   ### Brief Description
   
   Two independent per-message allocation reductions:
   
   1. **`MessageClientIDSetter.createUniqID()`**: replaces `new char[LEN * 2]` 
per call with a `ThreadLocal<char[]>` that is allocated once per thread and 
reused. The char array is only used to build the msgId string within the method 
and does not escape. JFR shows ~405 `char[]` allocation events/60s from this 
site eliminated.
   
   2. **`MessageVersion.valueOfMagicCode(int)`**: replaces `Enum.values()` 
(which copies the backing array per JDK spec) + O(n) loop with direct `if-else` 
matching on the two known magic code constants (`MESSAGE_MAGIC_CODE` and 
`MESSAGE_MAGIC_CODE_V2`). Eliminates the per-call array copy on the broker 
dispatch path.
   
   #### Compatibility
   
   - `createUniqID()` produces the same output format — only the internal char 
buffer allocation strategy changes.
   - `valueOfMagicCode()` behavior is identical for all valid inputs. Invalid 
magic codes still throw `IllegalArgumentException`.
   
   ### How Did You Test This Change
   
   ```bash
   mvn -pl common -Dcheckstyle.skip=false -Dspotbugs.skip=true validate
   # 0 Checkstyle violations
   
   mvn -pl common -Dcheckstyle.skip -Dspotbugs.skip=true -Djacoco.skip=true test
   # All tests pass
   ```


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