vue-router
vue-router copied to clipboard
WIP: Optimized matcher
This is a draft implementation with some new ideas.
- Static paths don't need regex match for most cases.
- Match don't have to be always linear, it is possible to match only with static paths.
Regex match is 10x slower than simple object access. I still have to run some dynamic matches to not break ordering compatibility.
I still want to integrate it better with current code, I did this implementation to validate the issue and run some benchmarks.
✔️ Deploy Preview for vue-router-docs-v3 canceled.
🔨 Explore the source changes: 7b4b0843bd08c25a3b10da5fa828f01ade7bc5cd
🔍 Inspect the deploy log: https://app.netlify.com/sites/vue-router-docs-v3/deploys/61f6f32903b198000767f58d
I did a small benchmark script to prove the concept, in my own machine.
https://gist.github.com/iurisilvio/a916ce2de16336ec97aab8db5525f7f9
For 100 static routes, current vue-router takes 14ms average to resolve and my version takes less than 1ms.
Even to resolve the first result, it is 30% slower because it evaluates one regex.
For dynamic paths, it will evaluate only part of the routes, based on first level path. If you have 100 rules but only 5 starting with the same first level path, it will evaluate at most 5 rules.