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
Performance degradation when using many routes in comparison to Nuxt 2 #25612
Comments
Start a new pull request in StackBlitz Codeflow. |
This issue is affecting the Openverse Nuxt 3 migration. We have around 20 routes multiplied by the number of locales, which is more than 50. It seems that Nuxt creates a new router per user request.
Each call to When I was researching the memory leak in Openverse Nuxt 3 migration branch, I often saw the |
We do need to create a router per-request. But if there's something preventing it from being garbage collected that should definitely be investigated. Would be worth trying to test without Nuxt via https://stackblitz.com/github/nuxt-contrib/vue3-ssr-starter to see if we can rule out For what it's worth, I'm not seeing a huge memory leak when running the reproduction provided by @BobbieGoede. It basically stays at around ~18Mb heap size on my machine for each siege batch. But happy to look into it a bit more... |
I have updated your reproduction without Nuxt to generate 1101 pages, you can find it here, note this doesn't accept Without Nuxt the performance also deteriorates in the same way in proportion to the number of routes, so I think we can assume that changes made between To me it looks like the main suspect would be Is it possible for routes to be different at router creation in Nuxt or does this essentially stay the same at the start of each request (route changes happen after creation)? I'll look into potential ways of caching some expensive calculations at router creation. |
Thank you - great investigation ❤️ We should probably raise this in https://github.com/nuxt/nuxt/blob/2.x/packages/vue-app/template/index.js#L94-L96 |
An update on this issue, I raised the issue in The maintainer has suggested ways on how the performance can be improved (custom matcher and matcher pre-compilation) so I'm going to do some research and (hopefully) work on a solution soon 😄. If you have thoughts or suggestions on a good way to implement these, feel free to leave them on the issue! |
Environment
n/a
Reproduction
I adapted and simplified reproduction from #25362 to generate ~1100 routes, all routes share the same component/page (index). I have kept the projects pretty much empty or unchanged other than that.
Nuxt 2
https://stackblitz.com/edit/github-4f1tg8?file=nuxt.config.js
Nuxt 3
https://stackblitz.com/edit/github-ibrygb?file=nuxt.config.ts
Build each project and test the performance of each project using
ab
orsiege
and compare the results. The projects can be built again while passingPATH_MULTIPLIER
(default:100
), this way you can rebuild the projects with more or fewer routes to see how that changes the results.Describe the bug
111 routes (
PATH_MULTIPLIER=10
)siege -t 10s -c 100 "http://localhost:3000/"
1101 routes (
PATH_MULTIPLIER=100
)siege -t 10s -c 100 "http://localhost:3000/"
I also ran tests using
ab
withab -n 1000 -c 50 http://localhost:3000/
, leaving results out for legibility (and formatting is tedious).Additional context
Users migrating from Nuxt 2 to Nuxt 3 while using the Nuxt I18n module experience memory and performance issues, due to the way routes are generated for i18n it results in the amount of routes in a project multiplied by the amount of configured languages.
Of course I will be looking into ways to improve this on the i18n module side, but as it is, the amount of routes in a project has a large impact on its performance, much more so in Nuxt 3 than in Nuxt 2.
Logs
No response
The text was updated successfully, but these errors were encountered: