Skip to content

Increase min_semi_space_size when possible to make v8 default heap space sizes less catastrophic for containers and memory-constrained environments #62723

@jedwards1211

Description

@jedwards1211

What is the problem this feature will solve?

Since upgrading from Node 20 to 24, I've been struggling to figure out why our production app memory usage slowly increases, but then the app starts becoming responsive instead of running OOM.

@mcollina I just ran into your article on Node.js heap tuning which mentions the following, and explains a lot about what I've been seeing. But ARGH why wasn't this in the release notes for Node 22??? This was crucial to warn people about so they don't get shafted!

An essential nuance in V8's memory management emerged around the Node.js v22 release cycle concerning how the default size for the New Space semi-spaces is determined. Unlike some earlier versions with more static defaults, newer V8 versions incorporate heuristics that attempt to set this default size dynamically, often based on the total amount of memory perceived as available to the Node.js process when it starts. This is highly relevant for applications deployed in containers (like Docker on Kubernetes) or serverless platforms (like AWS Lambda or Google Cloud Functions) where memory limits are often set relatively low (e.g., 512MB, 1GB, 2GB). In such scenarios, V8's dynamic calculation might result in an unexpectedly small default --max-semi-space-size, sometimes as low as 1 MB or 8 MB.

... Therefore, for applications running on Node.js v22 or later within memory-limited contexts, relying solely on the default V8 settings for semi-space size is generally discouraged. Developers should strongly consider profiling their application and explicitly setting the --max-semi-space-size flag

What is the feature you are proposing to solve the problem?

In such scenarios, V8's dynamic calculation might result in an unexpectedly small default --max-semi-space-size, sometimes as low as 1 MB or 8 MB.

Prevent this from happening by passing a default min_semi_space_size to V8 with a high enough value that the auto semi space size doesn't go below what older versions of Node used, unless the user overrides it or other constraints given by the user/detected available memory are so low that would be unreasonable.

What alternatives have you considered?

This is making me question whether I can trust Node.js maintenance to be predictable going forward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions