next.js: High memory usage in development (10GB+)

Link to the code that reproduces this issue

https://github.com/diogomartino/next-app-router-playground

To Reproduce

  1. Start the app in dev mode
  2. Open every single route you have available
  3. Memory usage keeps rising like crazy. The more routes you have, the more the RAM rises.

Current vs. Expected behavior

I expected that NextJS didn’t use 10GB.

Provide environment information

Ubuntu 22.04.5 LTS x86_64
Kernel: 6.8.0-57-generic

pnpm 7.33.5

Node v20.13.1
next: 15.2.3

Using turbo.

Which area(s) are affected? (Select all that apply)

Performance

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

So I made a script that fetches every single route for my project and plotted the RAM usage so you can see it increasing. As soon as all routes are fetched at least once, the memory usage stabilizes.

Image

For my project, the next-server starts at like 300 MB and rises all the way up to 9-10 GB. I also tried a template from vercel (https://vercel.com/templates/next.js/app-directory) and the same happens, but it’s not so noticeable because the code is much simpler and it has fewer routes. In the template case, it wen’t up to like 4GB, which is already too much.

I also tried with the most recent version (15.3.0) and it’s the same.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 20
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@diogomartino this is part of the prioritized list of issues. We’ll get to it soon.

This problem is not new; I have reported it myself before, but there has never been an adequate response. The high memory consumption has also been impacting our production environments. As an alternative, we decided to abandon Next.js and explore alternative solutions until a definitive solution is implemented.

Hey @diogomartino, thanks for digging into this and adding the scripts.

I did some digging based on the repository + scripts and found this is caused by an chunking optimization we had to rework a bit for Turbopack production builds. It redoes some work between routes now that can be shared. We were already tracking applying that optimization again. We’ll prioritize a fix 🙏

We’re also going to add benchmarks for many modules in a layout and then having a lot of page.tsx, that’s the specific case that reproduces this. Current benchmarks are mostly checking many modules on one page.

@icyJoseph yes, all my env is on the first post 👍

Still happening on v15.4.0-canary.97 seems like production build has reached 100% coverage, so congrats 🎉 but leaving some issues behind on development, more significantly memory usage and performance specially when having multiple views opened.

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

Great, then we can use all of this, to try and narrow down a canary between 15.2.x and 15.1.0 ~ I’ll see if I can get some time later today, but by all means go ahead