Skip to content

Conversation

@mxsm
Copy link
Member

@mxsm mxsm commented Nov 10, 2022

Make sure set the target branch to develop

What is the purpose of the change

close #5507

Brief changelog

  • Improve the speed of AttributeParser#parseToMap parsing
  • Polish code

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.

Copy link
Contributor

@caigy caigy left a comment

Choose a reason for hiding this comment

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

Although those variables should be constant, are there any test results to show the exact effect in improving the speed of parsing?

Comment on lines 27 to 33
public static final String COMMA = ",";

public static final String EQUAL_SIGN = "=";

public static final String PLUS_SIGN = "+";

private static final String MINUS_SIGN = "-";
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls use more descriptive names, like 'ATTR_ARRAY_SEPARATOR'.

Copy link
Member Author

@mxsm mxsm Nov 11, 2022

Choose a reason for hiding this comment

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

@caigy test result on related issue

Although those variables should be constant, are there any test results to show the exact effect in improving the speed of parsing?

image
split two times

@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 5, time = 5)
@Threads(1)
@Fork(1)
@State(value = Scope.Benchmark)
@OutputTimeUnit(TimeUnit.SECONDS)
public class SplitBenchmark {

    private String bbb = "1111,2222";

    @Benchmark
    public void splitTwo() {
        String s = bbb.split(",")[0];
        String s1 = bbb.split(",")[1];
    }

    @Benchmark
    public void splitOne() {
        String[] split = bbb.split(",");
        String s = split[0];
        String s1 = split[1];
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
            .include(SplitBenchmark.class.getSimpleName())
            .result("result.json")
            .resultFormat(ResultFormatType.JSON).build();
        new Runner(opt).run();
    }
}

benchmark result:
image

those variables should be constant is polish code

Copy link
Member Author

Choose a reason for hiding this comment

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

Pls use more descriptive names, like 'ATTR_ARRAY_SEPARATOR'.

I will do, thanks for you suggest

lizhanhui
lizhanhui previously approved these changes Nov 11, 2022
@mxsm mxsm dismissed stale reviews from lizhanhui and tsunghanjacktsai via 1b8a261 November 11, 2022 12:49
@mxsm mxsm requested a review from lizhanhui November 11, 2022 12:49
@codecov-commenter
Copy link

Codecov Report

Merging #5508 (1b8a261) into develop (a5b40fb) will decrease coverage by 0.19%.
The diff coverage is 42.75%.

@@              Coverage Diff              @@
##             develop    #5508      +/-   ##
=============================================
- Coverage      42.92%   42.72%   -0.20%     
+ Complexity      8069     8023      -46     
=============================================
  Files           1029     1029              
  Lines          72662    72672      +10     
  Branches        9604     9604              
=============================================
- Hits           31191    31052     -139     
- Misses         37527    37683     +156     
+ Partials        3944     3937       -7     
Impacted Files Coverage Δ
...ava/org/apache/rocketmq/acl/common/Permission.java 92.68% <ø> (ø)
...apache/rocketmq/acl/plain/PlainAccessResource.java 57.57% <ø> (ø)
...pache/rocketmq/acl/plain/PlainAccessValidator.java 78.57% <ø> (ø)
...che/rocketmq/acl/plain/PlainPermissionManager.java 78.22% <ø> (-0.54%) ⬇️
...a/org/apache/rocketmq/broker/BrokerController.java 43.55% <ø> (ø)
...apache/rocketmq/broker/BrokerPreOnlineService.java 0.00% <ø> (ø)
...java/org/apache/rocketmq/broker/BrokerStartup.java 7.74% <0.00%> (ø)
...ache/rocketmq/broker/client/ConsumerGroupInfo.java 68.46% <ø> (ø)
...roker/client/DefaultConsumerIdsChangeListener.java 40.74% <ø> (ø)
...ache/rocketmq/broker/client/net/Broker2Client.java 6.83% <ø> (ø)
... and 641 more

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

Comment on lines 27 to 33
public static final String ATTR_ARRAY_SEPARATOR_COMMA = ",";

public static final String ATTR_ARRAY_SEPARATOR_EQUAL_SIGN = "=";

public static final String ATTR_ARRAY_SEPARATOR_PLUS_SIGN = "+";

private static final String ATTR_ARRAY_SEPARATOR_MINUS_SIGN = "-";
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact not all of these constants are separators, pls give them names showing the exact purpose of them, eg. : What's the meaning of 'plus' or 'minus' in the context of attribute parsing?
BTW, I'd prefer making these constant fields as private, for they are not referenced outside AttributeParse.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact not all of these constants are separators, pls give them names showing the exact purpose of them, eg. : What's the meaning of 'plus' or 'minus' in the context of attribute parsing? BTW, I'd prefer making these constant fields as private, for they are not referenced outside AttributeParse.

I see what you mean, thanks for you suggest, I will polish this code again.

Copy link
Member

@hzh0425 hzh0425 left a comment

Choose a reason for hiding this comment

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

LGTM

@mxsm
Copy link
Member Author

mxsm commented Dec 1, 2022

@lizhanhui PTAL~

@RongtongJin RongtongJin merged commit fa22a78 into apache:develop Jan 12, 2023
@mxsm mxsm deleted the rocketmq-5507 branch January 12, 2023 03:08
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.

Improve the speed of AttributeParser#parseToMap parsing

7 participants