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.
We can significantly speed up route matching by not using
URLPattern
and opting for a custom constructedRegExp
instead. This is roughly 150-180x faster and I confirm that in live traces this greatly reduces CPU time.benchmark time (avg) iter/s (min … max) p75 p99 p995 --------------------------------------------------------------- ----------------------------- pattern 160.12 µs/iter 6,245.2 (151.88 µs … 712.62 µs) 161.04 µs 191.46 µs 221.21 µs regex 889.44 ns/iter 1,124,305.9 (870.65 ns … 965.37 ns) 892.66 ns 965.37 ns 965.37 ns
I've added an additional optimization that first checks if we're dealing with a pattern or an exact path match in the first place. If it's an exact match we can skip parsing it to a pattern entirely, which is even faster.