You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doc: clarify default heap size formula since node 12 #39107
I am not clear on the value of heap size for my instance. Given a formula/calculator, a user can then know for sure the default value based on the GB of memory available. It would be great to have this in the docs.
I would like to work on this issue and
submit a pull request.
I found this issue after digging around what happens if you don't specify --max-old-space-size. And since the code linked above is a bit hard for me to understand, I simply ran some tests with docker.
I spun up a container with docker run -it node:18 node and changed the memory limit in Docker Desktop between the runs.
I got the heap size with Math.round(require('v8').getHeapStatistics().total_available_size / (1024 * 1024)).
I also double checked the total memory amount with Math.round(require("os").totalmem() / 1024 / 1024) in parenthesis.
Docker memory
totalmem()
heap size
1 GB
915 MB
466 MB
2 GB
1919 MB
980 MB
4 GB
3928 MB
2007 MB
6 GB
5934 MB
2092 MB
8 GB
7946 MB
2091 MB
12 GB
11958 MB
2092 MB
15.5 GB
15479 MB
2091 MB
16 GB
15982 MB
4140 MB
So the behaviour is a bit weird between after 4 GB I would say. The 2 GB limit is a bit low, especially for servers with just below 16 GB of RAM (like Heroku's performance-l dyno with 14 GB of RAM). And the jump at 16 GB is also strange. I don't have easy access to a computer with more than 16 GB of RAM, but I suspect it will stay at 4 GB looking at the code above.
I also ran docker run -it node:18 node --max-old-space-size=5120 to verify the heap size and I got 5164 MB in that case.
I'm probably not the one to document this, but I wanted to share it regardless if anyone finds it useful!
Reacted by Sylvain Maucourt, Aymeric Robini, Leon Kiefer, Zack Corr, Jason Hoetger, Eddie Bachle, Martin Klinke and Luke Albao
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Activity
naseemkullah commentedon Jun 22, 2021
Hey @gtp-m3 I am not a maintainer of node and so cannot assign you. Hopefully one will see this and assign you to it! Thanks.
Ayase-252 commentedon Jun 23, 2021
@gtp-m3
Thanks for your help. It is yours.
BTW, you can work on any issue without prior assignment. Good luck.
Ayase-252 commentedon Jun 23, 2021
Should a paragraph to mention the default heap size be sufficient? IMO, a calculator seems too "heavy" to maintain.
naseemkullah commentedon Jun 23, 2021
Yes just a sentence as to how it's calculated exactly. Maybe with 2 or 3 examples with different available memory for clarity
targos commentedon Jun 23, 2021
References:
node/deps/v8/src/heap/heap.cc
Lines 239 to 254 in d65514b
node/deps/v8/test/unittests/heap/heap-unittest.cc
Lines 77 to 97 in d65514b
jasikpark commentedon Feb 14, 2022
Is this pertinent?:
node/deps/v8/src/heap/heap.cc
Lines 300 to 312 in d65514b
I'm currently trying to sort out what the max possible setting is + at what breakpoints does node choose which settings?
I want to max out my performance for a CI run :)
SomaSharath commentedon Dec 3, 2023
Hey @naseemkullah @targos @Ayase-252
Any idea, if someone is working on this? It'd be nice if this can be clarified please
johanarnor commentedon Feb 13, 2024
I found this issue after digging around what happens if you don't specify
--max-old-space-size. And since the code linked above is a bit hard for me to understand, I simply ran some tests with docker.I spun up a container with
docker run -it node:18 nodeand changed the memory limit in Docker Desktop between the runs.I got the heap size with
Math.round(require('v8').getHeapStatistics().total_available_size / (1024 * 1024)).I also double checked the total memory amount with
Math.round(require("os").totalmem() / 1024 / 1024)in parenthesis.So the behaviour is a bit weird between after 4 GB I would say. The 2 GB limit is a bit low, especially for servers with just below 16 GB of RAM (like Heroku's performance-l dyno with 14 GB of RAM). And the jump at 16 GB is also strange. I don't have easy access to a computer with more than 16 GB of RAM, but I suspect it will stay at 4 GB looking at the code above.
I also ran
docker run -it node:18 node --max-old-space-size=5120to verify the heap size and I got 5164 MB in that case.I'm probably not the one to document this, but I wanted to share it regardless if anyone finds it useful!
github-actions commentedon Jun 27, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
github-actions commentedon Jul 28, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.