Skip to content

Optimization around constructing UriTemplate with multiple template variables of the same type #1775

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

Closed

Conversation

MikeRocke
Copy link
Contributor

when supplying TemplateVariables of same Type.

This is done to reduce the repeated merge routines on ExpandGroups

I believe the current implementation degrades when more template variables are added, to demonstrate this

    @Benchmark
    @Fork(warmups = 1, value = 1)
    public void concat() {
        List<TemplateVariable> templateVariables = new LinkedList<>();
        for (int i = 0; i < 30; i++) {
            templateVariables.add(new TemplateVariable("a" + i, TemplateVariable.VariableType.REQUEST_PARAM));
        }
        TemplateVariables variables = new TemplateVariables(templateVariables);

        String uri = "http://localhost/autotrader/makes";
        UriTemplate template = UriTemplate.of(uri, variables);

    }

Results

Before

Benchmark                Mode  Cnt     Score    Error  Units
BenchmarkRunner.concat  thrpt    5  8177.940 ± 55.365  ops/s

After


Benchmark                Mode  Cnt       Score       Error  Units
BenchmarkRunner.concat  thrpt    5  109527.885 ± 20025.995  ops/s

Hope this is ok and helpful! :)

…plateVariables of same Type.

This is done to reduce the repeated merge routines on ExpandGroups
@MikeRocke
Copy link
Contributor Author

Closing this off for now. Happy to re-open if revisted

@MikeRocke MikeRocke closed this May 22, 2022
@odrotbohm odrotbohm reopened this Jun 1, 2022
odrotbohm pushed a commit that referenced this pull request Jun 1, 2022
…emplateVariables of same type

Reduce the repeated merge routines on ExpandGroups.

Before:
Benchmark                          Mode  Cnt     Score     Error  Units
TemplateVariableBenchmark.concat  thrpt    3  3150,261 ± 263,525  ops/s

After:
Benchmark                          Mode  Cnt      Score      Error  Units
TemplateVariableBenchmark.concat  thrpt    3  55275,436 ± 3778,690  ops/s
odrotbohm added a commit that referenced this pull request Jun 1, 2022
Avoid grouping of template variables via stream.

Before:

Benchmark                          Mode  Cnt      Score      Error  Units
TemplateVariableBenchmark.concat  thrpt    3  55275,436 ± 3778,690  ops/s

After:

Benchmark                          Mode  Cnt      Score     Error  Units
TemplateVariableBenchmark.concat  thrpt    3  64587,790 ± 735,705  ops/s
@odrotbohm
Copy link
Member

Sorry, this stayed unhandled for so long. Significant improvements. I've also additionally removed the streaming to group the variables in the first place and could bump the numbers by an additional 16%.

@odrotbohm odrotbohm self-assigned this Jun 1, 2022
@odrotbohm odrotbohm added type: enhancement in: core Core parts of the project labels Jun 1, 2022
@odrotbohm odrotbohm added this to the 2.0 M4 milestone Jun 1, 2022
@odrotbohm odrotbohm changed the title Small optimisation around constructing UriTemplate Optimization around constructing UriTemplate with multiple template variables of the same type Jun 1, 2022
@odrotbohm odrotbohm closed this Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants