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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiating Vue Router everytime causes serious performance problem #7473

Closed
asd123freedom opened this issue Jun 6, 2020 · 10 comments
Closed

Comments

@asd123freedom
Copy link

asd123freedom commented Jun 6, 2020

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

This bug report is available on Nuxt community (#c10737)
@ghost ghost added the cmty:bug-report label Jun 6, 2020
@asd123freedom asd123freedom changed the title instantiating Vue Router everytime causes serious performance problem Instantiating Vue Router everytime causes serious performance problem Jun 6, 2020
@manniL
Copy link
Member

manniL commented Jun 6, 2020

Possibly related: nuxt-modules/i18n#690 (comment)

@manniL manniL added the pending label Jun 6, 2020
@asd123freedom
Copy link
Author

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.

@vodnicearv
Copy link

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?

@asd123freedom
Copy link
Author

I've tried this week and failed . Vue SSR Guide tells developers that we also need a fresh router instance for each request

@chenfengyanyu
Copy link

chenfengyanyu commented Jun 16, 2020

I ran into the same problem and located the Vue-Router section.

First, through Clinic analysis, addRouteRecord causes CPU-intensive calculations, as shown below:

addRouterRecord

Secondly, the escapeString function will cause QPS loss, the data is as follows:

escapeString

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 ''

}

escapeString

There is a lot of route matching here, is there a more efficient way to solve it?Any help will be appreciated.

@pi0
Copy link
Member

pi0 commented Jun 16, 2020

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.

@asd123freedom
Copy link
Author

asd123freedom commented Jun 23, 2020

@pi0 looking forward to your solution

@yaowei520
Copy link

@pi0
Is there any progress on this issue?

@stouch
Copy link

stouch commented Dec 31, 2021

Any news about this ?

@danielroe danielroe added the 2.x label Jan 18, 2023
@danielroe
Copy link
Member

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.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants