-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Bug: extremely high memory usage with next dev
#42514
Comments
Probably related to #42349, when I profiled memory half of the heap was strings and they were also increasing with each request |
This comment was marked as outdated.
This comment was marked as outdated.
issue still persists in v13.0.3. |
I also have this issue. |
Same for me. A couple of times a day i get this error. Restarting the dev server helps |
Restarting the server helps but it's annoying to restart the server everytime. |
Yeah after the server crashes for JavaScript heap out of memory I just start up the server again, but it's inconvenient and annoying. Also it's taking a lot of memory usage while the app is running, so that's also very annoying since the app is functioning slower and compiling slower (by a lot). |
Don't misunderstand me, this was just meant as a temporarily fix. I also find it extremely annoying and i am worried that this might also happen in production... |
It'll probably not happen in production since its being compiled while building it and also it's a lot more optimized but yeah that's worrying. |
For me it happens in production too, Next 12 was working well with 500 Mb of RAM, now it gets out of memory on the first page reload |
Same problem here ! |
Release npm i [email protected] # npm
# or
yarn add [email protected] # yarn on your current project. It shouldn't break stuff that's already working. Also try to eliminate some dependencies that you don't need or that have a lighter alternative. Here's the release. |
I am on 13.0.4 and it still happened to me a couple of times today. This is the latest stack trace: `<--- Last few GCs ---> [21540:000001D236F10AA0] 1498088 ms: Mark-sweep 4065.1 (4138.6) -> 4053.0 (4142.6) MB, 270.3 / 0.1 ms (average mu = 0.208, current mu = 0.056) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory |
13.0.4 does not resolve the memory issue for me, still have the random out of memory crashes in development, I haven't encountered any issues in production though. |
I know that Material UI has some issues with NextJS 13, so if you're using that I'd suggest removing it and using a lighter solution. If you're not using it, try to remove dependencies that may cause an extremely high memory usage. Of course it's NextJS 13's fault, but removing dependencies might improve it. |
This is still happening to me on next 13.0.4 |
still happening to me |
Still bugging for me also 13.0.4 |
Still happening 13.0.5-canary.4 |
Still happening for me on 13.0.4 also 😕 |
For me in 13.0.4 the memory is still high but improved since 13.0.3 |
Still not fixed in 13.0.5 |
still happening 13.0.6-canary.2 |
Same issue here with latest canary. |
This is an extremely annoying problem. We are a website design agency. We migrated one of our websites to Next.js 13 (13.0.5) and it's using more than 900MBs of RAM. The same site in ASP.NET Core Pages used less than 100 MBs. Vercel, at least give us hints on how to debug this issue on our side. |
The same problem happened to me. I am using version 13.0.5, and the same problems have occurred frequently in previous versions. |
same problem here, using the with apollo example from here https://github.com/vercel/next.js/tree/canary/examples/with-apollo |
## Context There has been [some reports ](#42514 OOMs-related crashes with Next 13. Whilst we're fixing the memory leaks that are causing this, some of which are caused by upstream issues, this PR makes Next.js' dev server restarts if it detects that it is gonna crash soon. You can disable this behaviour by passing `__NEXT_DISABLE_MEMORY_WATCHER=1` to the env process. ## Details Under the hood, we're using Node's cluster API to create a child worker that will basically watch the memory usage after every request and then kill itself if it goes over 90% of the maximum heap allowance. ## Test plan I added manually a leaking function that I called before handling a request. I then manually tested that the server re-started when we were near the limit. ``` function createMemoryLeak() { console.log('createMemoryLeak', process.memoryUsage().heapUsed / 1024 / 1024) for (let i = 0; i < 10; i++) { buffer.push(new Array(1000000).fill('a')) } } ``` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) 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`](https://github.com/vercel/next.js/blob/canary/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)
The fix has landed on canary, please try it out and let me know if it makes your experience better. We're still blocked on the Node.js bug and we're investigating how we can solve this but I don't expect that it'll be fixed fast :/ . |
@feedthejim Thanks, it seems a combination of solutions you've implemented has eased the amount of crashing that occurs in the latest Canary release. One thing that i find really strange is how slow my app takes to compile when switching pages during development mode, Could this be some cause of the prefetching of links you described earlier? In Production, this is a non-existent issue - lightning fast, but developing is really tedious at the moment. |
I have tested the app with last canary release. We aren't writing "yarn dev" any more .(heyy). We have lost our productivity on the server after migrating 13. We were expecting to see magics that announced on everywhere. Working on this server now is just so frustrating. |
Thanks for the feedback @adshodgson @soylemezali42! @adshodgson I will surface that to the team... that's definitely something on my mind as well. @soylemezali42 can you expand more on not using yarn dev anymore? Also, is your other feedback related to page slowness? |
## Context There has been [some reports ](#42514 OOMs-related crashes with Next 13. Whilst we're fixing the memory leaks that are causing this, some of which are caused by upstream issues, this PR makes Next.js' dev server restarts if it detects that it is gonna crash soon. You can disable this behaviour by passing `__NEXT_DISABLE_MEMORY_WATCHER=1` to the env process. ## Details Under the hood, we're using Node's cluster API to create a child worker that will basically watch the memory usage after every request and then kill itself if it goes over 90% of the maximum heap allowance. ## Test plan I added manually a leaking function that I called before handling a request. I then manually tested that the server re-started when we were near the limit. ``` function createMemoryLeak() { console.log('createMemoryLeak', process.memoryUsage().heapUsed / 1024 / 1024) for (let i = 0; i < 10; i++) { buffer.push(new Array(1000000).fill('a')) } } ``` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) 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`](https://github.com/vercel/next.js/blob/canary/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)
How about the production environment? |
Hi @Nefcanto, can you open a new issue with a repro of your setup/what operations you noticed increased memory usage? |
next dev
Watching this carefully, as I have a Next project with about 12 pages and 260 static pages. 547MB free mem, and it dies rather quickly |
The Production build seems to run fine for me, really quick. The fixes @feedthejim suggested, regarding changing the Memory Limit, and also the patches introduced have stopped the server from crashing in Development mode. I think the only serious problem for me, seems to be how slow the App is in Development mode - when trying to navigate between pages, I can sometimes wait for up to 8-10 seconds for each page to switch - Whilst in production it's almost instantaneous. I'm unsure the cause, just hinders productivity quite dramatically. |
Do you fetch data in layout ? I just found out that fetching in layout reduce a lot development mode. |
@adshodgson do you mind sharing a repro (preferably via codesanbox or similar tool)? I can take a look. There's a few things that can slow down dev times:
|
@feedthejim I sent you an invitation here. This is one of our real-world examples. We are a website design company. We use Next.js as our website tech and other technologies for our backend and API. We're still using Next.js 12. We used ASP.NET Core Razor Pages before and we had much more density per server. We could host 10 websites per 1GB of RAM. Now we're limited to 1 or 2 at most. This has increased our hosting costs drastically and we're thinking of migrating to another tech, like Qwik maybe. But if we can get lower RAM in production, then we're good to continue using Next.js. @feedthejim, I would gladly send you remote access to my PC and I would continue the debugging session with you if you want to. I would guide you through our architecture (though it's not hard at all), and explain how we use Next.js. Just let me know. Thank you so much. |
I'm also encountering this and can share a repo.
|
Hi all! |
Any official fix yet? still happening for me and |
@logann131 can you try upgrading and report back if it still happens? |
Also facing this issue, memory climbs to ~5GB while it should be ~30MB. |
@mooijtech on a dev or prod instance? |
@feedthejim Long story short, turns out the memory leak is not related to NextJS but Tauri (https://tauri.app/) caused by the I will open an issue there. Thanks for your reply. |
I notice using |
@dexter4life can you perhaps open an issue with a repo? I'll be closing this issue as the frequency of the reports seems to have lessened a bit. Please open an issue with repro steps if you encounter issues again! |
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. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Chrome Canary v109.0.5400.0 (Android)
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
The memory usage on the last next 13 (13.0.3-canary.0 and 13.0.2) releases are too high.
next dev
command uses about 1gb of ram. Next 12 is using about 300mb-500mb's of ram.Expected Behavior
next dev
should use less ram.Link to reproduction
.
To Reproduce
next dev
The text was updated successfully, but these errors were encountered: