Copilot commented on code in PR #10469:
URL: https://github.com/apache/rocketmq/pull/10469#discussion_r3388999766


##########
common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java:
##########
@@ -111,8 +111,10 @@ public static int getPidFromID(String msgID) {
         return value & 0x0000FFFF;
     }
 
+    private static final ThreadLocal<char[]> UNIQ_ID_BUF = 
ThreadLocal.withInitial(() -> new char[LEN * 2]);
+
     public static String createUniqID() {
-        char[] sb = new char[LEN * 2];
+        char[] sb = UNIQ_ID_BUF.get();

Review Comment:
   Using a static `ThreadLocal` will retain a `char[]` per live thread 
(including threads in pools) for the lifetime of the thread, which can increase 
retained memory in environments with many threads. If the allocation savings 
are important, consider documenting this tradeoff in a short comment near 
`UNIQ_ID_BUF`; otherwise, consider falling back to allocating per call (since 
the buffer is small) or ensuring there’s an appropriate lifecycle point to 
`remove()` when threads are short-lived.



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