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

   ### What this PR does
   
   Enhance `FastCodesHeader` interface and `RocketMQSerializable` utility to 
reduce allocation and CPU overhead in the Remoting header encoding/decoding hot 
path.
   
   ### Changes
   
   **`FastCodesHeader.java`**
   - Optimize `writeIfNotNull` to route `Long`/`Integer` values through 
`writeDecimalLong`/`writeDecimalInt` instead of `value.toString()` + 
`writeStr`, eliminating transient `String` allocation.
   - Add `writeLong(ByteBuf, String, long)` and `writeInt(ByteBuf, String, 
int)` helper methods for direct primitive encoding.
   
   **`RocketMQSerializable.java`**
   - Add `writeDecimalLong(ByteBuf, long)` and `writeDecimalInt(ByteBuf, int)` 
— write decimal numbers directly to `ByteBuf` without `String.valueOf()` 
allocation.
   - Add `SINGLE_BYTE_STRINGS` cache (128 entries) — `readStr` returns cached 
`String` for single-byte ASCII values instead of creating new `String` via 
`readCharSequence`.
   - Right-size `mapDeserialize` initial `HashMap` capacity from 128 to 24 — 
typical headers have 5-15 entries, 128 causes unnecessary memory waste.
   
   All changes are **additive** — no existing method signatures are modified.
   
   ### Benchmark Results
   
   A/B test on remote servers (256 threads, 1KB sync send, Dragonwell JDK 21, 
6g heap):
   
   | Metric | Baseline (develop) | Optimized (R1) | Change |
   |--------|-------------------|----------------|--------|
   | TPS | ~196k | ~236k | **+20.6%** |
   | p99 RT | 3ms | 2ms | **-33%** |
   | Average RT | 1.307ms | 1.085ms | **-17.0%** |
   | Max RT | 594ms | 351ms | **-40.9%** |
   | Young GCs (total) | 336 | 304 | **-9.5%** |
   
   ### Commercial Compatibility
   
   - Pure additive changes — no existing API signatures modified.
   - No commercial classes implement `FastCodesHeader`.
   - Commercial `YitianRemotingCommand` calls 
`RocketMQSerializable.rocketMQProtocolDecode/Encode` which are unchanged.
   


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