Skip to content
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

[ISSUE #5859]Optimize String#format in DefaultMQProducerImpl #5870

Merged
merged 2 commits into from
Jan 17, 2023

Conversation

mxsm
Copy link
Member

@mxsm mxsm commented Jan 11, 2023

Make sure set the target branch to develop

What is the purpose of the change

close #5859

Brief changelog

  • Optimize String#format in DefaultMQProducerImpl

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

Comment on lines 698 to 702
StringBuilder info = new StringBuilder(300);
info.append("Send [").append(times).append("] times, still failed, cost [")
.append(System.currentTimeMillis() - beginTimestampFirst).append("]ms, Topic: ").append(msg.getTopic())
.append(", BrokersSent: ").append(Arrays.toString(brokersSent))
.append(FAQUrl.suggestTodo(FAQUrl.SEND_MSG_FAILED));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the String.format is more readable here

Copy link
Member Author

@mxsm mxsm Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the String.format is more readable here

@RongtongJin This optimization has been done from a performance perspective. The performance of String.format is relatively poor and triggers an array expansion, which can be referenced in issue #5804 . However, readability has been reduced.Performance enhancement should be considered as the first priority. Or Add a comment that enhances readability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, these transitions are all in the exception scene,

it will lost a little performance when in the little scene,

so we can choose the readability when in this scene.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MoreObjects.toStringHelper of guava or ToStringBuilder of commons-lang is more readable

@mxsm mxsm requested a review from RongtongJin January 12, 2023 15:29
@codecov-commenter
Copy link

Codecov Report

Merging #5870 (60e0e53) into develop (5894332) will decrease coverage by 0.08%.
The diff coverage is 20.75%.

@@              Coverage Diff              @@
##             develop    #5870      +/-   ##
=============================================
- Coverage      42.48%   42.40%   -0.09%     
- Complexity      8248     8283      +35     
=============================================
  Files           1060     1066       +6     
  Lines          73473    73670     +197     
  Branches        9616     9629      +13     
=============================================
+ Hits           31215    31239      +24     
- Misses         38334    38476     +142     
- Partials        3924     3955      +31     
Impacted Files Coverage Δ
...cketmq/broker/longpolling/NotificationRequest.java 0.00% <0.00%> (ø)
...broker/processor/AbstractSendMessageProcessor.java 33.22% <ø> (+0.50%) ⬆️
...ocketmq/broker/processor/PeekMessageProcessor.java 3.22% <0.00%> (ø)
...he/rocketmq/broker/processor/PopReviveService.java 39.62% <0.00%> (ø)
...mq/client/impl/producer/DefaultMQProducerImpl.java 46.17% <0.00%> (-0.25%) ⬇️
...org/apache/rocketmq/store/DefaultMessageStore.java 52.91% <ø> (ø)
...a/org/apache/rocketmq/store/stats/BrokerStats.java 0.00% <0.00%> (ø)
...cketmq/broker/processor/NotificationProcessor.java 10.16% <3.44%> (-0.74%) ⬇️
...pache/rocketmq/store/stats/BrokerStatsManager.java 50.29% <53.84%> (-0.02%) ⬇️
...ker/processor/DefaultPullMessageResultHandler.java 38.46% <100.00%> (ø)
... and 45 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@RongtongJin RongtongJin merged commit c82ab44 into apache:develop Jan 17, 2023
@mxsm mxsm deleted the rocketmq-5859 branch January 17, 2023 08:48
drpmma pushed a commit that referenced this pull request Feb 21, 2023
* [ISSUE #5859]Optimize String#format in DefaultMQProducerImpl

* polish code
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.

Optimize String#format in DefaultMQProducerImpl
6 participants