Improved HTTP server route matching with performant hybrid implementation - #751
Open
GoodforGod wants to merge 8 commits into
Open
Improved HTTP server route matching with performant hybrid implementation#751GoodforGod wants to merge 8 commits into
GoodforGod wants to merge 8 commits into
Conversation
Renamed HttpServerHandler to HttpServerRouter Optimized and improved HttpServerRouter Optimized and improved PathTemplateMatcher & PathTemplate
…erminal wildcard validation Improved route lookup performance by introducing compressed radix and adaptive hybrid decision matching with builder-compiled immutable state. - Added strict validation that wildcard segments are allowed only at the end of a route. - Moved legacy matcher variants to test fixtures for compatibility benchmarks. - Added benchmarks covering shared stems, route groups, and matcher strategies.
Test Results158 tests 158 ✅ 11m 22s ⏱️ Results for commit 101d785. ♻️ This comment has been updated with latest results. |
Contributor
Author
Change for WildcardNow a wildcard is valid only when Valid examples: Invalid examples: Invalid templates fail during router construction rather than producing ambiguous or implementation-dependent runtime matching. Terminal wildcards participate in normal route priority and may follow literal or parameter segments. |
Dependency Update ReportUpdate level: Found
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Improved HTTP server route matching with immutable hybrid radix and decision tries
EN
Improved HTTP route lookup performance and scalability by replacing the mutable legacy runtime matcher with an immutable hybrid matcher that combines exact-path lookup, a compressed radix trie, and per-stem segment decision tries. The final implementation preserves route priority and parameter-capture semantics, validates terminal wildcards at startup, and removes synchronization and volatile state access from request processing.
RU
Улучшена производительность и масштабируемость HTTP-маршрутизации за счёт immutable Hybrid matcher, объединяющего exact-path lookup, compressed radix trie и segment decision trie для конфликтующих групп маршрутов. Финальная реализация сохраняет приоритеты маршрутов и семантику параметров, валидирует wildcard при запуске и убирает синхронизацию и volatile-доступ из request hot path.
HybridPathTemplateMatcheras the production matcher used byHttpServerRouter.RadixPathTemplateMatcheras the compressed-radix baseline and fallback strategy for non-conflicting routes.*to the final character of a route template.Performance
All reported values use JMH
AverageTimeinns/op; lower is better.The broad comparison used:
Due to lower bench params some regressions or lower final results may be for new impl, next proper detailed recheck affirms that.
¹ The short-run single-parameter measurements were non-monotonic and had large errors, especially for Hybrid. They were superseded by the dedicated full-profile run below.
Hybrid provides the best exact-path result at every tested route count. It also wins every multiple-parameter case, two of three wildcard cases, and the 1024-route miss case. Radix remains slightly faster for small misses because it avoids Hybrid’s per-stem strategy dispatch.
Stabilized single-parameter comparison
The dedicated benchmark isolates unique-stem routes of the form:
Only Original and Hybrid were measured using the extended two-fork profile.
The single-param bench comparison used:
Taking the stabilized single-parameter measurements into account, Hybrid wins 12 of the 15 general scenario/route-count combinations.
Shared static stems
This scenario places every route in one conflicting stem group:
At 1024 conflicting routes, Hybrid is faster than:
Fanout and decision-threshold comparison
The fanout benchmark keeps 128 total routes and varies candidates per shared stem from 1 to 128.
It covers:
EARLY_FANOUT, where literal alternatives appear immediately after the shared prefix;DEEP_FANOUT, where alternatives appear after additional common parameter and literal segments;WILDCARD_FANOUT, where each candidate ends in a terminal wildcard;Geometric means across all group sizes:
Hybrid wins 42 of the 48 exact
shape × groupSize × hit/misscombinations.Diagnostic Hybrid modes confirm that decision compilation provides the improvement:
DEFAULT_DECISION_THRESHOLD = 2therefore keeps the direct single-holder path when a stem uniquely identifies one route and compiles every genuine collision into a decision trie. The default policy tracks always-decision performance, while forced linear matching regresses toward Radix as collision groups grow.Design
Exact-path index
Routes without parameters or wildcards are compiled into an immutable exact-path map.
Lookup begins with:
The stored result already contains:
Exact hits therefore require no trie traversal and reuse a prebuilt match result.
This is why Hybrid produces the best exact-path result at all tested route counts.
Compressed radix stem index
Dynamic routes are grouped by their static stem and inserted into a compressed radix tree.
A regular character trie would represent:
Per-stem strategy selection
Each radix terminal is compiled into one of three forms:
Single holder
Used when the stem uniquely identifies one route. No candidate list or decision trie is needed.
Linear matcher
Retained for groups that cannot safely start segment decisions at the stem boundary.
Decision matcher
Used for compatible stem groups with at least
DEFAULT_DECISION_THRESHOLDcandidates.The default threshold is two.
Wildcard contract
A wildcard is valid only when
*is the final character of the template.Valid examples:
Invalid examples:
Invalid templates fail during router construction rather than producing ambiguous or implementation-dependent runtime matching.
Terminal wildcards participate in normal route priority and may follow literal or parameter segments.
Compatibility
The public
HttpServerRouterconstruction and routing contract remains unchanged.The matcher preserves:
404and405behavior;The stricter wildcard validation intentionally rejects templates containing a non-terminal
*during startup.Validation