Closed
Description
Affected URL(s)
Description of the problem
The docs read:
The default value is 16 MiB for 64-bit systems and 8 MiB for 32-bit systems. To get the best configuration for your application, you should try different max-semi-space-size values when running benchmarks for your application.
This may have been true in Node 18 but in the newer version of v8 (11.3) used in Node 20, the default scales with the memory limit, and will generally be less than this documented value.
Running the example from the docs on Node 18:
docker run -it -m 2g \
-e NODE_OPTIONS="--max-old-space-size=1536" \
node:18 node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
1584
1584-1536 = 48MB = 3 x max-semi-space-size
Now in Node 20:
docker run -it -m 2g \
-e NODE_OPTIONS="--max-old-space-size=1536" \
node:20 node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
1560
1560-1536 = 24MB, so max-semi-space-size
defaults to 8 here 👈
In order to run with the same heap size limit in Node 20, you must explicitly set the max-semi-space-size
:
docker run -it -m 2g \
-e NODE_OPTIONS="--max-old-space-size=1536 --max-semi-space-size=16" \
node:20 node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
1584
👉 1584-1536 = 48MB, same as Node 18