qianye1001 opened a new pull request, #10401:
URL: https://github.com/apache/rocketmq/pull/10401

   ## Summary
   Cache `Version.values()` in a static final field to eliminate repeated 
defensive-copy array allocations in hot-path methods `getVersionDesc()` and 
`value2Version()`.
   
   ## Problem
   `Version.values()` returns a defensive copy of a 943-element enum array on 
every call. These two methods call it 6 times total, allocating ~7.5KB of heap 
per invocation. Under high throughput (broker heartbeats, client connections), 
this creates unnecessary GC pressure.
   
   ## Fix
   - Added `private static final Version[] VERSION_VALUES = Version.values();` 
(initialized once at class load)
   - Rewrote both methods to use a local reference to the cached array
   - Public API signatures unchanged — pure internal optimization, zero 
behavioral change
   
   ## Changes
   | File | Change |
   |------|--------|
   | `common/.../MQVersion.java` | Cache enum array, rewrite 2 methods |
   
   ## Related Issue
   Closes #10400
   
   ---
   *This PR was automatically generated.*


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