Navigation Menu

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

Speed up AntPathMatcher by doing prefix-match #958

Closed
wants to merge 1 commit into from

Conversation

soldierkam
Copy link
Contributor

Many ant style patterns has prefix that can be used to determine if there is no need to do complicated and costly matching.
For example pattern "/static/css/*" have prefix "/static/css/" that can be used to say that path "/api/resource/1234" will not match.

This was tested with https://gist.github.com/soldierkam/c80e433aa9fbec35df5a
Before:

Benchmark Mode Cnt Score Error Units
MyBenchmark.isMatching thrpt 5 425995,288 ± 162966,573 ops/s
MyBenchmark.isNotMatching thrpt 5 864690,507 ± 130643,210 ops/s
MyBenchmark.suffix thrpt 5 748551,270 ± 17229,496 ops/s

After:

Benchmark Mode Cnt Score Error Units
MyBenchmark.isMatching thrpt 5 483815,001 ± 105669,816 ops/s
MyBenchmark.isNotMatching thrpt 5 10208718,438 ± 125879,376 ops/s
MyBenchmark.suffix thrpt 5 624841,454 ± 349001,674 ops/s

Result: over 10x faster for isNotMatching and 17% slower for "suffix" case.

I tested it with https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-rest (wrk -c 40 -d 30 -t 2 http://127.0.0.1:8080/api/hotels) but results are almost the same (before: 310.15req/seq, after: 305.41req/sec).
For https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-actuator-ui (wrk -c 40 -d 30 -t 2 http://localhost:8080/css/bootstrap.min.css) there is small perf improvement - before: 2237.90req/seq, after: 2353.93req/sec
For real world application (that contains many more endpoints) I've got 17% more throughput for endpoint serving static resource (baseline is at 1812req/sec).

Let me know what you think.

@bclozel bclozel self-assigned this Feb 3, 2016
@bclozel
Copy link
Member

bclozel commented Feb 10, 2016

Thanks @soldierkam for this PR! I'd be happy to review more if you've got other ideas 👍

Indeed, I ran a few JMH benchmarks myself and found that this leads to a consistent performance boost for many cases. AntPathMatcher is a central piece of our infrastructure, so I'm not keen on backporting this change to the latest version of the 4.2.x line. This will be shortly available as a 4.3.0-BUILD-SNAPSHOT version.

Merged as e77ff3c for SPR-13913

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.

None yet

2 participants