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

   ## Summary
   
   Replace `Enum.values()` + O(n) loop with static `BY_CODE[]` array for O(1) 
lookup in `LanguageCode.valueOf(byte)` and `SerializeType.valueOf(byte)`.
   
   ### Problem
   
   JDK requires `Enum.values()` to return a fresh array on every call 
(defensive copy). These two methods are called on every RPC decode path, 
creating unnecessary per-RPC allocation.
   
   ### Fix
   
   Build a static lookup array at class load time:
   
   ```java
   private static final LanguageCode[] BY_CODE;
   static {
       int max = 0;
       for (LanguageCode lc : values()) max = Math.max(max, lc.code & 0xFF);
       BY_CODE = new LanguageCode[max + 1];
       for (LanguageCode lc : values()) BY_CODE[lc.code & 0xFF] = lc;
   }
   public static LanguageCode valueOf(byte code) {
       int idx = code & 0xFF;
       return idx < BY_CODE.length ? BY_CODE[idx] : null;
   }
   ```
   
   Same pattern for `SerializeType` (2 values: JSON=0, ROCKETMQ=1).
   
   ### Files Changed
   
   | File | Change |
   |---|---|
   | `remoting/.../protocol/LanguageCode.java` | +15/-6: `BY_CODE[]` static 
array + O(1) `valueOf(byte)` |
   | `remoting/.../protocol/SerializeType.java` | +4/-6: `BY_CODE[]` static 
array + O(1) `valueOf(byte)` |


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