Skip to content

[heap] Restore original heap size#371

Open
IlyasShabi wants to merge 1 commit into
mainfrom
ishabi/restore-initial-limit
Open

[heap] Restore original heap size#371
IlyasShabi wants to merge 1 commit into
mainfrom
ishabi/restore-initial-limit

Conversation

@IlyasShabi

@IlyasShabi IlyasShabi commented Jul 8, 2026

Copy link
Copy Markdown

What does this PR do?:

Register V8’s AutomaticallyRestoreInitialHeapLimit when installing the near-heap-limit callback to 95% of original size.
When live old-generation heap usage drops below threshold * original_heap_limit, restore the max heap limit back to the original heap limit.

Motivation:
MonitorOutOfMemory extends V8’s heap limit so the profiler has enough space to collect and export heap profiler. Currently if the application frees memory and recovers, that extended heap limit can remain in place which makes the headroom effectively permanent and can allow later memory growth beyond the original budget.

@IlyasShabi IlyasShabi added the semver-patch Bug or security fixes, mainly label Jul 8, 2026
@IlyasShabi IlyasShabi changed the title restore original heap size [heap] Restore original heap size Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Overall package size

Self size: 2.41 MB
Deduped: 3.11 MB
No deduping: 3.11 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.2.2 | 500.53 kB | 500.53 kB | | source-map | 0.7.6 | 185.63 kB | 185.63 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@IlyasShabi IlyasShabi force-pushed the ishabi/restore-initial-limit branch from e143f44 to dc629db Compare July 8, 2026 15:18
if (isolate) {
isolate->AddNearHeapLimitCallback(&NearHeapLimit, nullptr);
// Restore 90% of the original heap limit when possible.
constexpr double kHeapLimitRestoreThreshold = 0.90;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the current size is 90% of the original one, we consider that v8 recovered and restore the original one.

@IlyasShabi IlyasShabi marked this pull request as ready for review July 8, 2026 15:21
@datadog-datadog-prod-us1

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-patch Bug or security fixes, mainly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant