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

Extremely high memory usage

Open budchirp opened this issue 2 years ago • 13 comments

Verify canary release

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

Provide environment information

Operating System:
  Platform: android
  Arch: arm64
  Version: #2 SMP PREEMPT Fri Aug 5 15:52:33 AST 2022
Binaries:
  Node: 18.10.0
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.0.3-canary.0
  eslint-config-next: 13.0.2
  react: 18.2.0
  react-dom: 18.2.0

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.

Screenshot_20221104-225938_Termux

Expected Behavior

next dev should use less ram.

Link to reproduction

.

To Reproduce

  1. Create project with Next 13
  2. Run next dev
  3. Check the ram usage

budchirp avatar Nov 05 '22 15:11 budchirp

Probably related to #42349, when I profiled memory half of the heap was strings and they were also increasing with each request

remorses avatar Nov 06 '22 09:11 remorses

Issue still persists in 13.0.3-canary.1.

ariesclark avatar Nov 08 '22 10:11 ariesclark

issue still persists in v13.0.3.

ariesclark avatar Nov 12 '22 01:11 ariesclark

I also have this issue.

AlonHor avatar Nov 13 '22 15:11 AlonHor

Same for me. A couple of times a day i get this error. Restarting the dev server helps

arthureberledev avatar Nov 15 '22 09:11 arthureberledev

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.

budchirp avatar Nov 15 '22 10:11 budchirp

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).

AlonHor avatar Nov 15 '22 16:11 AlonHor

Same for me. A couple of times a day i get this error. Restarting the dev server helps

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...

arthureberledev avatar Nov 16 '22 15:11 arthureberledev

Same for me. A couple of times a day i get this error. Restarting the dev server helps

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.

AlonHor avatar Nov 16 '22 17:11 AlonHor

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

remorses avatar Nov 16 '22 17:11 remorses

Seems to constantly crash for me on Next13

image

adshodgson avatar Nov 17 '22 16:11 adshodgson

Same problem here ! If a page have lot of <Link>, Next prebuilt all of these pages resulting high memory consumption and slow down of the app.

Alexandredc avatar Nov 18 '22 13:11 Alexandredc

Release 13.0.4 seemed to had fixed it for me. You can update by doing:

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.

AlonHor avatar Nov 18 '22 16:11 AlonHor

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
[21540:000001D236F10AA0] 1498502 ms: Mark-sweep 4069.0 (4142.6) -> 4056.9 (4146.6) MB, 396.8 / 0.1 ms (average mu = 0.115, current mu = 0.040) allocation failure scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF62B780AAF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+124015 2: 00007FF62B70C866 v8::internal::wasm::WasmCode::safepoint_table_offset+64182 3: 00007FF62B70D8E2 v8::internal::wasm::WasmCode::safepoint_table_offset+68402 4: 00007FF62C041CE4 v8::Isolate::ReportExternalAllocationLimitReached+116 5: 00007FF62C02C2AD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62BECF88C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468 7: 00007FF62BECC9A4 v8::internal::Heap::CollectGarbage+4244 8: 00007FF62BECA320 v8::internal::Heap::AllocateExternalBackingStore+2000 9: 00007FF62BEE8030 v8::internal::FreeListManyCached::Reset+1408 10: 00007FF62BEE86E5 v8::internal::Factory::AllocateRaw+37 11: 00007FF62BEFA68E v8::internal::FactoryBasev8::internal::Factory::AllocateRawArray+46 12: 00007FF62BEFD2CA v8::internal::FactoryBasev8::internal::Factory::NewFixedArrayWithFiller+74 13: 00007FF62BEFD523 v8::internal::FactoryBasev8::internal::Factory::NewFixedArrayWithMap+35 14: 00007FF62BD03B96 v8::internal::HashTablev8::internal::NameDictionary,v8::internal::NameDictionaryShape::EnsureCapacityv8::internal::Isolate+246 15: 00007FF62BD0193A v8::internal::Dictionaryv8::internal::NameDictionary,v8::internal::NameDictionaryShape::Addv8::internal::Isolate+58 16: 00007FF62BD09B66 v8::internal::BaseNameDictionaryv8::internal::NameDictionary,v8::internal::NameDictionaryShape::Add+118 17: 00007FF62BC16858 v8::internal::Runtime::GetObjectProperty+1720 18: 00007FF62C0CF9C1 v8::internal::SetupIsolateDelegate::SetupHeap+494417 19: 000001D23A365117 error Command failed with exit code 134.`

arthureberledev avatar Nov 18 '22 21:11 arthureberledev

Release 13.0.4 seemed to had fixed it for me. You can update by doing:

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.

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.

ariesclark avatar Nov 20 '22 07:11 ariesclark

Release 13.0.4 seemed to had fixed it for me. You can update by doing:

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.

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.

AlonHor avatar Nov 20 '22 11:11 AlonHor

This is still happening to me on next 13.0.4

LorenzoBloedow avatar Nov 21 '22 00:11 LorenzoBloedow

still happening to me

andrewdoro avatar Nov 21 '22 07:11 andrewdoro

Still bugging for me also 13.0.4

adshodgson avatar Nov 21 '22 11:11 adshodgson

Still happening 13.0.5-canary.4

Mistwell avatar Nov 22 '22 09:11 Mistwell

Still happening for me on 13.0.4 also 😕

pedronauck avatar Nov 23 '22 00:11 pedronauck

For me in 13.0.4 the memory is still high but improved since 13.0.3

AlonHor avatar Nov 23 '22 13:11 AlonHor

Still not fixed in 13.0.5

budchirp avatar Nov 25 '22 18:11 budchirp

still happening 13.0.6-canary.2

soylemezali42 avatar Nov 30 '22 15:11 soylemezali42

Same issue here with latest canary. Just after start 2,5GB of ram for a rather simple app, and after a bit of time = crash.

OtisTemler avatar Dec 02 '22 12:12 OtisTemler

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.

Nefcanto avatar Dec 04 '22 10:12 Nefcanto

The same problem happened to me.

I am using version 13.0.5, and the same problems have occurred frequently in previous versions.

m1nsuplee avatar Dec 04 '22 14:12 m1nsuplee

same problem here, using the with apollo example from here https://github.com/vercel/next.js/tree/canary/examples/with-apollo

image

aaronkchsu avatar Dec 04 '22 17:12 aaronkchsu

Hey folks, next.js team member here. I'm investigating this issue. Would anyone care to share with me privately their projects so I can investigate properly? Or a public repro?

feedthejim avatar Dec 05 '22 14:12 feedthejim

@feedthejim sure, I can create a public repo that works with a public API. I need some time though to create it. Maybe a day.

Nefcanto avatar Dec 05 '22 14:12 Nefcanto