next.js
next.js copied to clipboard
Next useCache option set to `false` which causes each request to require everything all over again.
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Wed Oct 5 21:31:17 UTC 2022
Binaries:
Node: 16.18.0
npm: 8.19.2
Yarn: N/A
pnpm: 7.14.0
Relevant packages:
next: 13.0.2-canary.0
eslint-config-next: 12.3.1
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
next start
Describe the Bug
In next 12.3.2 a change was made that turns off cacheing of required modules: https://github.com/vercel/next.js/blob/canary/packages/next/server/next-server.ts#L2132 . I imagine the reason for that was some problems when running next on serverless functions. Because of that when running next in a node environment (using next start or custom next server) each request requires all modules everytime, which takes ages. Overall the performance of next ran using next start dropps dramatically in 12.3.2 and later versions.
Average response time with cache enabled is around 50ms. With cache disabled 500ms. 10x worse performance. And it gets even worse when handling multiple requests at the same time.
Expected Behavior
Allow users to set this flag from config or decide if cache should be used based on runtime.
When cache is set to true reuse cached modules (that part is already happening when useCache is true).
Link to reproduction
https://stg.parkschannel.app.elpassion.com/
To Reproduce
Just visit the page and see how fast it is loading.
Example node performance summary when running same page locally:
- Without cache: (you can see that require takes around 72% CPU + it's blocking so all of the process is blocked by it)
- With cache enabled (I've changed the flag in built app to true), (you can see that require is long gone below webpack_require which is non blocking, so we can leverage node async io to still serve a lot of requests):
I'll only add that I think this issue is critical. Basically all non edge hosted apps got hit a lot (performance wise) with this change.
I would be very happy to support with analyzing / explaining the problem and trying to fix it.
Great work
The problem was probably introduced here: https://github.com/vercel/next.js/commit/889af9fd2c68a8b03b5fec34c8651e43e15bfa1e in 12.3.2-canary.29 which explains why it's a problem also in other issues.
Same problem here. Lighthouse performance score goes down from 95 to 53. Time to interactive is up to 12.5 seconds. If I remove the middleware it is back to normal.
The above patch is now available in v13.0.3-canary.1
of Next.js, please update and give it a try!
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.