Skip to content

[ISSUE#9435]:Flow control optimization #9434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Guiqu1aixi
Copy link

@Guiqu1aixi Guiqu1aixi commented May 27, 2025

I think there is no significant difference between logging a warning every 1000 times versus every 1024 times. However, changing 1000 to 1024 allows replacing the modulo operation with a bitwise and operation, which can achieve a performance optimization in every calculation cycle, Thank you for your patience in reviewing this。

Which Issue(s) This PR Fixes

Fixes #9435

Brief Description

How Did You Test This Change?

…every 1000 times versus every 1024 times. However, changing 1000 to 1024 allows replacing the modulo operation with a bitwise AND operation, which can achieve a performance optimization in every calculation cycle.
@Guiqu1aixi Guiqu1aixi changed the title Flow control optimization [ISSUE#9435]:Flow control optimization May 27, 2025
@Guiqu1aixi
Copy link
Author

Guiqu1aixi commented Jun 3, 2025

使用JMH基准测试,两种场景:平均耗时,每秒吞吐,
先预热三轮,结合MQ的实际场景,被求余的数字不会很大,因此设置最小边界是0,最大20480
结果如下:

@Guiqu1aixi
Copy link
Author

Guiqu1aixi commented Jun 3, 2025

吞吐还有耗时的提升大概都在2%左右
thrpt:
Benchmark (number) Mode Cnt Score Error Units
ModVsBitmaskBenchmarkT.bitwise 0 thrpt 4 585542159.635 ± 4617347.105 ops/s
ModVsBitmaskBenchmarkT.bitwise 1000 thrpt 4 584290537.081 ± 16650492.968 ops/s
ModVsBitmaskBenchmarkT.bitwise 1024 thrpt 4 584381389.631 ± 5641034.048 ops/s
ModVsBitmaskBenchmarkT.bitwise 2000 thrpt 4 584370743.001 ± 5346549.000 ops/s
ModVsBitmaskBenchmarkT.bitwise 2048 thrpt 4 584875587.741 ± 2605739.696 ops/s
ModVsBitmaskBenchmarkT.bitwise 4000 thrpt 4 585558087.640 ± 5470804.999 ops/s
ModVsBitmaskBenchmarkT.bitwise 4096 thrpt 4 584200651.599 ± 12188292.420 ops/s
ModVsBitmaskBenchmarkT.bitwise 10000 thrpt 4 584816113.774 ± 11292858.085 ops/s
ModVsBitmaskBenchmarkT.bitwise 10240 thrpt 4 585215359.048 ± 5118577.383 ops/s
ModVsBitmaskBenchmarkT.bitwise 20000 thrpt 4 583738725.485 ± 9722227.841 ops/s
ModVsBitmaskBenchmarkT.bitwise 20480 thrpt 4 584743944.006 ± 7697864.815 ops/s
ModVsBitmaskBenchmarkT.mod 0 thrpt 4 575176030.964 ± 32486341.103 ops/s
ModVsBitmaskBenchmarkT.mod 1000 thrpt 4 574770730.766 ± 25603862.399 ops/s
ModVsBitmaskBenchmarkT.mod 1024 thrpt 4 572824030.325 ± 10800376.130 ops/s
ModVsBitmaskBenchmarkT.mod 2000 thrpt 4 578344039.587 ± 4655626.485 ops/s
ModVsBitmaskBenchmarkT.mod 2048 thrpt 4 577338763.882 ± 9739121.340 ops/s
ModVsBitmaskBenchmarkT.mod 4000 thrpt 4 578568934.054 ± 7858263.877 ops/s
ModVsBitmaskBenchmarkT.mod 4096 thrpt 4 577444347.683 ± 11004118.322 ops/s
ModVsBitmaskBenchmarkT.mod 10000 thrpt 4 578132939.319 ± 6522374.391 ops/s
ModVsBitmaskBenchmarkT.mod 10240 thrpt 4 576044853.107 ± 13600487.456 ops/s
ModVsBitmaskBenchmarkT.mod 20000 thrpt 4 574045434.464 ± 8018753.080 ops/s
ModVsBitmaskBenchmarkT.mod 20480 thrpt 4 576263325.180 ± 7363493.385 ops/s

avgt:
Benchmark (number) Mode Cnt Score Error Units
ModVsBitmaskBenchmark.bitwise 0 avgt 4 1.713 ± 0.016 ns/op
ModVsBitmaskBenchmark.bitwise 1000 avgt 4 1.711 ± 0.015 ns/op
ModVsBitmaskBenchmark.bitwise 1024 avgt 4 1.713 ± 0.011 ns/op
ModVsBitmaskBenchmark.bitwise 2000 avgt 4 1.713 ± 0.013 ns/op
ModVsBitmaskBenchmark.bitwise 2048 avgt 4 1.708 ± 0.020 ns/op
ModVsBitmaskBenchmark.bitwise 4000 avgt 4 1.714 ± 0.039 ns/op
ModVsBitmaskBenchmark.bitwise 4096 avgt 4 1.706 ± 0.014 ns/op
ModVsBitmaskBenchmark.bitwise 10000 avgt 4 1.710 ± 0.016 ns/op
ModVsBitmaskBenchmark.bitwise 10240 avgt 4 1.709 ± 0.004 ns/op
ModVsBitmaskBenchmark.bitwise 20000 avgt 4 1.708 ± 0.012 ns/op
ModVsBitmaskBenchmark.bitwise 204800 avgt 4 1.713 ± 0.039 ns/op
ModVsBitmaskBenchmark.mod 0 avgt 4 1.736 ± 0.028 ns/op
ModVsBitmaskBenchmark.mod 1000 avgt 4 1.737 ± 0.017 ns/op
ModVsBitmaskBenchmark.mod 1024 avgt 4 1.757 ± 0.064 ns/op
ModVsBitmaskBenchmark.mod 2000 avgt 4 1.751 ± 0.120 ns/op
ModVsBitmaskBenchmark.mod 2048 avgt 4 1.730 ± 0.022 ns/op
ModVsBitmaskBenchmark.mod 4000 avgt 4 1.739 ± 0.160 ns/op
ModVsBitmaskBenchmark.mod 4096 avgt 4 1.750 ± 0.035 ns/op
ModVsBitmaskBenchmark.mod 10000 avgt 4 1.746 ± 0.011 ns/op
ModVsBitmaskBenchmark.mod 10240 avgt 4 1.727 ± 0.026 ns/op
ModVsBitmaskBenchmark.mod 20000 avgt 4 1.723 ± 0.008 ns/op
ModVsBitmaskBenchmark.mod 204800 avgt 4 1.747 ± 0.066 ns/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Flow control optimization
1 participant