Skip to content

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

@michalwarda

Description

@michalwarda

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions