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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: speedup slow matching of static routes #1932

Merged
merged 2 commits into from
Oct 13, 2023
Merged

Conversation

marvinhagemeister
Copy link
Collaborator

@marvinhagemeister marvinhagemeister commented Oct 13, 2023

This PR speeds up matching static file routes. Previously, each static file route would get their own URLPattern instance which is slow and we loose the fact that we could do an exact match by doing so.

What this PR does is extend the type of a route pattern to be URLPattern | string. When it's a string than we treat it as being an exact match and sidestep the whole cost of doing a URL parse + regex match. Note that only we ourselves can create string-based patterns. User supplied patterns are always parsed into URLPattern like before.

Thanks to @jviide for the idea of adding caching for static routes 馃憤

In some real world sites I've tested this fix with this reduces route matching cost from 62ms -> 0.7ms

Fixes #1931

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.

router: URL-route matching is expensive
1 participant