-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instantiating Vue Router everytime causes serious performance problem #7473
Comments
Possibly related: nuxt-modules/i18n#690 (comment) |
Yes,it does. I guess it may be solved by using nuxt-community/router-module. With router-module I can make sure vue-router init only once. |
can You show your solution with router-module? |
I've tried this week and failed . Vue SSR Guide tells developers that we also need a fresh router instance for each request |
I ran into the same problem and located the Vue-Router section. First, through Clinic analysis, addRouteRecord causes CPU-intensive calculations, as shown below: Secondly, the escapeString function will cause QPS loss, the data is as follows: The source code of escapeString is as follows(QPS=891): function escapeString (str) {
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
} So, I tried as follows(QPS=1524): function escapeString (str) {
return '';
} There is a lot of route matching here, is there a more efficient way to solve it?Any help will be appreciated. |
Thanks, @chenfengyanyu for the benchmarks. It makes quite a sense If the route registration part is CPU-intensive, finding a way to cache/compute SSR routes once. But we cannot simply create a shared instance for SSR! So we probably need to see if there is a way in improving vue-router. |
@pi0 looking forward to your solution |
@pi0 |
Any news about this ? |
It's been quite some time and there's a new major version of vue-router. If anyone is still experiencing a problem with this, would you please open an issue upstream at https://github.com/vuejs/router with a reproduction? Feel free to tag me; I'd be happy to help look into this if so. |
Version
v2.8.1
Reproduction link
https://codesandbox.io/s/nuxt-middleware-rxzl4
Steps to reproduce
1.use wrk to simulate large scale of requests
2.remove lots of files from pages folder and simualte again
3.compare QPS between two reports generated from wrk
What is expected ?
The QPS numbers are close
What is actually happening?
If I remove files from pages folder, QPS will increase a lot.
Additional comments?
I looked into Server.js which is generated by nuxt-cli., and I found Vue Router is instanced every time. I assumed that it should be cached in case of performance problem
The text was updated successfully, but these errors were encountered: