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

Next useCache option set to false which causes each request to require everything all over again. #42349

Closed
1 task done
michalwarda opened this issue Nov 2, 2022 · 6 comments · Fixed by #42547
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@michalwarda
Copy link

michalwarda commented Nov 2, 2022

Verify canary release

  • 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:

  1. Without cache: (you can see that require takes around 72% CPU + it's blocking so all of the process is blocked by it)
    image
  2. 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):
    image
@michalwarda michalwarda added the bug Issue was opened via the bug report template. label Nov 2, 2022
@michalwarda
Copy link
Author

michalwarda commented Nov 2, 2022

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.

@11koukou
Copy link
Contributor

11koukou commented Nov 2, 2022

Great work

@michalwarda
Copy link
Author

The problem was probably introduced here: 889af9f in 12.3.2-canary.29 which explains why it's a problem also in other issues.

@michalwarda michalwarda changed the title Next useCache option set to false which causes request for everything require everything all over again. Next useCache option set to false which causes each request to require everything all over again. Nov 2, 2022
@quadrifolia
Copy link

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.

ijjk added a commit that referenced this issue Nov 6, 2022
Follow-up to #41402 this
re-enables the sandbox cache and updates to leverage our global
`AsyncLocalStorage` for isolating request meta in both the edge and
Node.js runtime.

Closes: #42349
Closes: #38235
Closes: #42225
Closes: #42351

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@ijjk
Copy link
Member

ijjk commented Nov 8, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

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 github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants