[ISSUE #9064]Optimize the way to determine whether RMQ_SYS_TRANS-HALFTOPIC is in RMQ_SSYS_TRANS-OP_ALF_TOPIC in transaction messages #9062
+4
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
fixes #9064
Brief Description
事务消息, 回查判断RMQ_SYS_TRANS_HALF_TOPIC消息是否在RMQ_SYS_TRANS_OP_HALF_TOPIC 中,优化判断方式。之前代码是先判断Map.containsKey,然后进行removeKey,新的方式是直接removeKey != null。之前如果Map.containsKey为真,还需要进行额外的一步removeKey操作,新的方式removeKey!= null,即判断了Map是否存在key,又移出了对应的key,提升了一点点性能。
Transactional messages: The process involves checking whether messages in RMQ_SYS_TRANS_HALF_TOPIC exist in RMQ_SYS_TRANS_OP_HALF_TOPIC, with an optimized approach for verification. Previously, the code first used Map.containsKey to check existence and then performed removeKey. The new approach directly uses removeKey != null.
In the previous method, if Map.containsKey returned true, an additional removeKey operation was required. In contrast, the new approach both checks if the key exists in the Map and removes the corresponding key in one step, offering a slight performance improvement.
How Did You Test This Change?
经过多轮测试,在Map.containsKey 为true为false概率各为50%的情况,第二种方案明显优于第一种方案。而实际生产环境中,事务回查状态为Unknown的场景应该小于50%,在高并发大数据量场景下,个人认为这个小改动对性能还是有一些提升。
After multiple rounds of testing, when the probabilities of Map.containsKey being true or false are both 50%, the second approach consistently outperforms the first. In actual production environments, the probability of transactional checks being in an “Unknown” state should be less than 50%. Therefore, I believe this small adjustment provides a minor but meaningful performance improvement.