Speed up AntPathMatcher by doing prefix-match #958
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
After:
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.