wang-jiahua opened a new issue, #10527: URL: https://github.com/apache/rocketmq/issues/10527
### Before Creating the Enhancement Request - [x] I have confirmed that this should be classified as an enhancement rather than a bug/feature. ### Summary Reduce allocation in auxiliary store components by replacing boxed maps with primitive atomics, caching string keys, reusing StringBuilders, and optimizing timer wheel flush. ### Motivation JFR profiling reveals several allocation hotspots in auxiliary store components that run on every message: 1. **`QueueOffsetOperator`** — uses `ConcurrentMap<String, Long>` for queue offsets, boxing every `long` update into a `Long` object and requiring map lookups. 2. **`BrokerStatsManager`** — `buildStatsKey`/`topicQueueKey`/`consumerOffset` methods create new strings on every call. `incQueue*` methods use `Integer` parameters causing autoboxing. 3. **`IndexService`** — builds index keys with `StringBuilder` allocated per-call. 4. **`TimerWheel`** — flushes all slots unconditionally, even when no changes occurred. ### Describe the Solution You'd Like 1. `QueueOffsetOperator`: Replace `ConcurrentMap<String, Long>` with `ConcurrentMap<String, AtomicLong>` — eliminates boxing on every update. 2. `BrokerStatsManager`: Cache `buildStatsKey`/`topicQueueKey`/`consumerOffset` string results. Change `Integer` parameters to `int` to eliminate autoboxing. 3. `IndexService`: Reuse `StringBuilder` via ThreadLocal. 4. `TimerWheel`: Add volatile `dirty` flag — skip flush when no changes since last flush. 5. `AppendMessageResult`: Add constructor with pre-computed fields to avoid redundant allocation. ### Describe Alternatives You've Considered - Use `LongAdder` instead of `AtomicLong` — `AtomicLong` is sufficient for moderate contention and provides `get()` for reads. - Use `String.format` cache — `String.concat` is faster for small fixed key patterns. - Use object pool for `StringBuilder` — ThreadLocal is simpler and thread-safe by design. ### Additional Context Part of a larger JFR-driven optimization effort. Related PRs: #10443, #10444, #10514, #10524, #10526. -- 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]
