fix(allocations): stop the heap sampling when getting profile#357
Merged
Conversation
Overall package sizeSelf size: 2.19 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 |
|
szegedi
approved these changes
Jun 25, 2026
Merged
szegedi
pushed a commit
that referenced
this pull request
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?:
In
ts/src/heap-profiler.ts, after eachprofile()call in allocation mode, stop and immediately restart the V8 sampling heap profiler with the original parameters. The stop call frees V8's sample buffer; the restart resumes sampling for the next window.Motivation:
When the heap profiler is started with allocations enabled, V8 retains a record of every sampled allocation. The only V8 API that frees that buffer is
StopSamplingHeapProfilerandGetAllocationProfiledoes not clear it.Today the binding never restarts the sampler between collections. Each call to
profile()re-aggregates the entire history of sampled allocations since the profiler was started, producing two issues:alloc_*totals grow ~N× across N consecutiveprofile()calls instead of reflecting the per-window allocation rate.Additional Notes:
Benchmark
Baseline
With the Fix