Skip to content

fix: avoid forced GC during allocation profile collection - #435

Merged
IlyasShabi merged 1 commit into
mainfrom
ishabi/profiling-remove-forced-gc
Nov 9, 2026
Merged

IlyasShabi merged 1 commit into
mainfrom
ishabi/profiling-remove-forced-gc

Conversation

@IlyasShabi

@IlyasShabi IlyasShabi commented Nov 7, 2026 •

Copy link
Copy Markdown

What does this PR do?

Removes kSamplingForceGC from allocation profiling on Node.js 26+, so collecting a profile no longer requests a full GC. It also updates the documentation in the code and adds a simple regression test.

Motivation

We identified that allocation profiling forces a full GC every time we collect a profile. This adds GC work and can cause long pauses on the main thread. Removing the flag avoids those extra collections and their pause overhead.

Additional Notes

Some objects that are no longer reachable may still be reported as live because V8 has not collected them yet. This can overestimate live heap usage at collection time. For a statistical profiler, we prefer this tradeoff to forcing a full GC on every profile.

Jira SCP-1457

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Overall package size

Self size: 2.62 MB
Deduped: 3.73 MB
No deduping: 3.73 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.4.0 | 912.36 kB | 912.36 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 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 added the semver-patch Bug or security fixes, mainly label Nov 7, 2026
@datadog-datadog-prod-us1-2

This comment has been minimized.

@IlyasShabi
IlyasShabi marked this pull request as ready for review November 9, 2026 08:47

@szegedi szegedi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, this does not even affect the precision of allocation profiles, since they report live + collected and the sum remains the same with or without GC, only the summands change. If anything, this improved the precision of heap live size profiles, since without it it can report samples for unreachable, but not yet collected objects as live, which is how it worked before allocation profiling anyway. Do I see it right?

@IlyasShabi

Copy link
Copy Markdown
Author

@szegedi Yes that’s right! Removing the flag affects the freshness of live heap, not the accuracy of allocation profiles.

@IlyasShabi
IlyasShabi merged commit ceb8321 into main Nov 9, 2026
126 of 129 checks passed
@IlyasShabi
IlyasShabi deleted the ishabi/profiling-remove-forced-gc branch November 9, 2026 10:55
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.

3 participants