next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Big Performance dropdown with middleware, latest nextjs and node version >=16.17.1

Open 11koukou opened this issue 2 years ago • 4 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System: Platform: win32 Arch: x64 Version: Windows 10 Enterprise LTSC 2021 Binaries: Node: 16.17.1 npm: N/A Yarn: N/A pnpm: N/A Relevant packages: next: 13.0.1-canary.2 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)

No response

Describe the Bug

After upgrading to latest next 12 canary or next 13 canary version,I have a huge performance drop (middleware enabled). It is pretty obvious when I load my website but also when I run lighthouse which reports a core of 51 instead of ~97 that i reported before the upgrade. If I either switch to latest next stable release or disable the middleware performance returns to normal levels. The same happens if I downgrade my nodejs version to 16.5.0 and keep the middleware and latest nextjs

related to https://github.com/vercel/next.js/issues/41551 , https://github.com/vercel/next.js/issues/38273

Expected Behavior

Performance should be kept high regardless nodejs version and middleware usage

Link to reproduction

https://github.com/11koukou/my-app

To Reproduce

Simply clone the project, npm install, npm run build, and npm start. Check out the performance and then disable/delete the "middleware.ts" file , repeat the steps and check the performance again. Without middleware lighthouse reports 100. The same happens if you just downgrade to next version 12.3.1 and keep the middleware enabled, or downgrade to nodejs 16.5.0 and keep the middleware and latest nextjs as well

11koukou avatar Oct 31 '22 10:10 11koukou

Any news on this? It is really hurting performance

11koukou avatar Nov 02 '22 13:11 11koukou

Everything starts with next version 12.3.2-canary.29

Prior to this everything works fine.

Next 12.3.1 : Untitled2

Next 12.3.2-canary.29 : Untitled

Same machine, same node version

11koukou avatar Nov 02 '22 14:11 11koukou

I think it's also related to: https://github.com/vercel/next.js/issues/42349

michalwarda avatar Nov 02 '22 15:11 michalwarda

I also have this issue. One thing that really improved my performance for me was by adding:

export const config = { matcher: '/about/:path*', }

The documentation states: Middleware will be invoked for every route in your project. Specifying specific routes seems to improve it greatly. Performance is still not as good as it is when removing middleware but it did make lighthouse green again. Hope this helps.

weskor avatar Nov 02 '22 15:11 weskor

I also have this issue. One thing that really improved my performance for me was by adding:

export const config = { matcher: '/about/:path*', }

The documentation states: Middleware will be invoked for every route in your project. Specifying specific routes seems to improve it greatly. Performance is still not as good as it is when removing middleware but it did make lighthouse green again. Hope this helps.

Thanks for your response, however I notice the same slow behavior even if I use middleware without any code at all inside the exported function

11koukou avatar Nov 02 '22 20:11 11koukou

The above patch is now available in v13.0.3-canary.1 of Next.js, please update and give it a try!

ijjk avatar Nov 08 '22 05:11 ijjk

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.

github-actions[bot] avatar Dec 08 '22 12:12 github-actions[bot]