[ISSUE #10538] Eliminate SendMessageRequestHeaderV2 intermediate object in client#10540
[ISSUE #10538] Eliminate SendMessageRequestHeaderV2 intermediate object in client#10540wang-jiahua wants to merge 2 commits into
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Eliminates per-send SendMessageRequestHeaderV2 intermediate object allocation by making SendMessageRequestHeader implement FastCodesHeader with V2 short-key wire format encoding/decoding. This removes 14 field copies per send on the client hot path.
Findings
-
[Info]
SendMessageRequestHeader.java— Theencode(ByteBuf)method correctly handles both V2 short keys (a–n) and V1 long keys (producerGroup, etc.) in the decode path. This ensures backward compatibility with older brokers/servers that may send V1 long keys. Well done. -
[Info]
SendMessageRequestHeader.java:parseRequestHeader()— The oldswitch(requestCode)fall-through logic (V2 → create V1 from V2) is replaced with a directdecode()call. This is correct because the newdecode()handles both V2 short keys and V1 long keys transparently. However, this is a subtle behavioral change — the old code had explicit request-code-based routing, while the new code relies ondecode()to handle all cases. Recommend ensuring integration tests cover both V1 and V2 request paths. -
[Info]
SendMessageRequestHeader.java— The addition of primitive-type setter overloads (setBornTimestamp(long),setQueueId(int),setQueueOffset(long)) alongside the boxed-type versions is a good pattern to avoid autoboxing on the hot path. The null-safe fallback to 0 insetBornTimestamp(Long)is correct. -
[Info]
SendMessageResponseHeader.java— Same primitive overload pattern applied. Clean.
Suggestions
-
Since this PR depends on #10535 (FastCodesHeader for V2 short-key encode), consider noting in the PR description that #10535 must be merged first. The dependency chain is clear from the code but worth stating explicitly.
-
The
decode()method inSendMessageRequestHeaderuses aswitchon key names for all 14 fields. If any new field is added to the header in the future, developers must remember to update bothencode()anddecode(). Consider adding a comment near the field declarations reminding about this coupling.
Overall: Clean, well-structured performance optimization. The backward compatibility handling in decode() is solid.
Automated review by github-manager-bot
Server Benchmark Results (2026-06-23)Environment: 8C30G broker, Dragonwell JDK 21, 1KB msg, 128 queues, sync mode, 256 threads, 20s warmup + 30s collect Producer-only (steady state, lines 3-5)
Client skip V2 intermediate object eliminates per-send SendMessageRequestHeaderV2 allocation + 14 field copies. TPS within noise band. GC reduction (-33%) confirms allocation savings on client side. |
…MessageRequestHeader Add hand-written encode()/decode() with V2 short-key support to SendMessageRequestHeader, eliminating reflection-based makeCustomHeaderToNet() on the Send request path.
fc9b269 to
65a5528
Compare
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review after new commits)
Summary
New commit adds V2 intermediate object elimination in MQClientAPIImpl and MQClientAPIExt — now uses SendMessageRequestHeader directly with V2 request codes instead of creating SendMessageRequestHeaderV2 wrapper objects.
CI Status
CI is failing — Checkstyle reports 2 UnusedImports violations:
MQClientAPIExt.java:92— unused importSendMessageRequestHeaderV2MQClientAPIImpl.java:233— unused importSendMessageRequestHeaderV2
The V2 class is no longer used in these files after this change. Remove both import statements.
Additionally, SpotBugs reports ES_COMPARING_PARAMETER_STRING_WITH_EQ in RemotingMetricsManager.getOrBuildAttributes() (lines 102-106). This appears to be from a concurrent change on the same branch — the result == RESULT_SUCCESS comparisons need to use .equals() instead of ==.
Findings
-
[Critical]
MQClientAPIImpl.java:233,MQClientAPIExt.java:92— Remove unusedSendMessageRequestHeaderV2imports to fix Checkstyle CI failure. -
[Info] The refactoring in
sendMessage()correctly simplifies the branching:sendSmartMsg ? RequestCode.SEND_REPLY_MESSAGE_V2 : RequestCode.SEND_REPLY_MESSAGEis clean and maintains the same wire protocol behavior. -
[Info]
MQClientAPIExt.sendMessageAsync()now passesrequestHeader(V1 type) directly withRequestCode.SEND_MESSAGE_V2code. This works becauseSendMessageRequestHeadernow implementsFastCodesHeaderwith V2 short-key encoding (from #10535). Correct.
Suggestions
- Fix the two unused imports — this is a quick one-line fix per file.
- Consider adding a brief note in the PR description about the dependency on #10535 being merged first.
Automated review by github-manager-bot
…e object in client Client now uses SendMessageRequestHeader directly with V2 short-key encode (from apache#10535), eliminating per-send V2 object creation + 14 field copies.
65a5528 to
885f563
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #10540 +/- ##
=============================================
- Coverage 48.26% 48.12% -0.15%
+ Complexity 13433 13414 -19
=============================================
Files 1377 1377
Lines 100844 100917 +73
Branches 13036 13062 +26
=============================================
- Hits 48672 48563 -109
- Misses 46221 46387 +166
- Partials 5951 5967 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review after new commit 885f563)
Summary
New commit confirmed — SendMessageRequestHeader now implements FastCodesHeader directly with V2 short-name encoding support. The SendMessageRequestHeaderV2 intermediate object has been fully eliminated from the client send path.
Assessment
- [Correctness] The encode/decode methods correctly handle both V1 (full field names) and V2 (short names: a, b, c...) protocols. The
parseRequestHeadermethod now decodes directly intoSendMessageRequestHeaderwithout V2 conversion. Logic is sound. - [Performance] Eliminates per-message object allocation on the hot path. Good optimization for high-throughput scenarios.
- [Compatibility] The V2 wire format is preserved — field names
a,b,cetc. are correctly mapped. Backward-compatible with existing brokers. - [Tests]
MQClientAPIImplTestupdated. Coverage looks adequate.
LGTM — all CI checks pass. Solid performance optimization. ✅
Automated by github-manager-bot
Which Issue(s) This PR Fixes
Fixes #10538
Brief Description
How Did You Test This Change
CI checkstyle + compilation passed. Server benchmark pending (depends on #10535 merge).