wang-jiahua opened a new pull request, #10444: URL: https://github.com/apache/rocketmq/pull/10444
Replace per-message HashMap allocation in the properties encode/decode hot path with a compact FlatPropertiesMap backed by a flat Object[] array. Add ThreadLocal reuse for the map, StringBuilder, and char[] buffers. Intern high-frequency property keys and values to eliminate redundant String allocation. <!-- Please make sure the target branch is right. In most case, the target branch should be `develop`. --> ### Which Issue(s) This PR Fixes <!-- Please ensure that the related issue has already been created, and [link this pull request to that issue using keywords](<https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>) to ensure automatic closure. --> - Fixes #10442 ### Brief Description <!-- Write a brief description for your pull request to help the maintainer understand the reasons behind your changes. --> Heap dump shows `HashMap$Node[]` occupies 21% of live heap and `String` has only 21,873 distinct values out of 100,000 sampled (e.g., `"true"` duplicated 7,142 times). The `string2messageProperties` / `messageProperties2String` path is the largest allocation hotspot on the broker send path. Changes: - **`FlatPropertiesMap`** (new): compact `Map<String, String>` backed by flat `Object[]`, supports `reset()` for ThreadLocal reuse, `computeEncodedLength()`, and `encodeTo(ByteBuffer)` for zero-copy serialization - **`MessageDecoder`**: byte-level `bytes2messageProperties(ByteBuffer)` parsing without `new String()` + `split()`; ThreadLocal `REUSABLE_PROPS_MAP` and `REUSABLE_SB` - **`MessageConst`**: `STRING_INTERN_BY_LEN` length-bucketed key intern array - **`MessageDecoder`**: `VALUE_INTERN_BY_LEN` for common value interning (`"true"`, `"false"`, `"DefaultRegion"`, etc.) - **`MessageClientIDSetter`**: ThreadLocal `char[]` for `createUniqID` - **`MessageVersion`**: direct if-else lookup replacing `values()` iteration JFR-measured bytes/msg reduction: **-42.7%** from this change alone. ### How Did You Test This Change? <!-- In order to ensure the code quality of Apache RocketMQ, we expect every pull request to have undergone thorough testing. --> - JFR profiling (ObjectAllocationSample) on 4×ECS (8c/30G), 128 producer threads, 1KB body, Temurin JDK 21 - Verified message encode/decode round-trip correctness - Send-path `string2messageProperties` returns `HashMap` (not `FlatPropertiesMap`) to maintain downstream compatibility -- 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]
