wang-jiahua opened a new issue, #10467: URL: https://github.com/apache/rocketmq/issues/10467
### Motivation JFR profiling on the producer send path and broker dispatch path reveals two unnecessary per-message allocations: 1. **`MessageClientIDSetter.createUniqID()`** — allocates a `new char[LEN * 2]` on every send. Since the char array is only used to build a msgId string and is immediately discarded, it can be reused via `ThreadLocal`. JFR shows ~405 events/60s from this site. 2. **`MessageVersion.valueOfMagicCode(int)`** — calls `MessageVersion.values()` which copies the enum values array on every invocation (JDK spec), then performs an O(n) linear scan. Since there are only two known magic codes, a direct if-else is both faster and avoids the array copy. ### Proposed Changes - `createUniqID()`: replace `new char[LEN * 2]` with `ThreadLocal<char[]>` initialized once per thread. - `valueOfMagicCode()`: replace `values()` loop with direct if-else matching the two known magic code constants. ### Impact - Eliminates ~405 char[] allocations per 60s on the producer side. - Eliminates per-call `Enum.values()` array copy on the broker dispatch path. -- 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]
