Repository navigation
[4/4] feat(heap): enable in-place sampling heap pruner and remove restart loop - #462
IlyasShabi wants to merge 4 commits into
Conversation
Overall package sizeSelf size: 2.98 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.4.1 | 924.37 kB | 924.37 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 |
…pruner-4-enable-pruner
…pruner-4-enable-pruner
szegedi
left a comment
There was a problem hiding this comment.
Again, approving this one too. All I have are nits, but of course if you fix any I'm happy to re-approve.
| startedWithAllocations = allocations; | ||
| startSamplingHeapProfiler(intervalBytes, stackDepth, allocations); | ||
| heapIntervalBytes = intervalBytes; | ||
| startedWithAllocations = allocations && usesInPlacePruner(); |
There was a problem hiding this comment.
On Windows/Node 26 and on Node 27+, start(i, d, true) now quietly falls back to live-only profiles. On main those runtimes got (restart-based) allocation profiles. I agree live-only is strictly better than a corrupted inuse_space, but we should call it out. Could we either:
(a) fix the JSDoc ("Requires Node.js >= 26" → requires Node 26 on non-Windows, otherwise falls back to live-only);
(b) give callers a way to know, either by documenting usesInPlacePruner() as the check or by returning it from start(), or warning once; and
(c) mention this in the PR description?
We should not forget to update usesInPlacePruner() for when Node.js 27 comes out as allocation mode will switch off for it, but I guess we'll get reminded by a falling CI if 27 gets added to the testing matrix, right? I think you'd want to first check if the internal layout stays the same or needs to be updated.
| if (state->allocations) { | ||
| // In allocation mode V8 retains dead samples in node->allocations; | ||
| // derive live-only counts from GetSamples() for the OOM report. | ||
| if (state->pruner.IsActive()) { |
There was a problem hiding this comment.
nit: Presuming live-only on pruner.IsActive() misses cases where V8 still keeps dead samples while the pruner isn't attached:
- a foreign sampler with
includeObjectsCollected*was already running at start(); - the gap between
BuildStats()settingpending_downgrade_andPrune()(translation allocates there).
In the first case regular profile() also counts dead objects as in-use. Could we do a data check instead? On Node >= 26, scan once with std::any_of(samples, !is_live) and only then build live-only stats. That's free in the common no-flags case and covers both paths.
| std::unique_ptr<v8::AllocationProfile> profile( | ||
| isolate->GetHeapProfiler()->GetAllocationProfile()); | ||
| if (!profile) { | ||
| return Nan::ThrowError("Heap profiler is not enabled."); |
There was a problem hiding this comment.
When GetAllocationProfile() returns null, our sampler is gone (an external stop). Resetting state->pruner here before throwing would stop usesInPlacePruner() from reporting true for a stale pointer, and would remove the window where the next sampler, possibly at the same address, gets mistaken for ours.
Stack
mainishabi/heap-pruner-1-lifecycle-perfBuildAllocationStatsByNodeIdand live-only near-OOM filteringishabi/heap-pruner-2-watermark-oomSamplingHeapPrunerimplementation + design docishabi/heap-pruner-3-sampling-prunerSamplingHeapPruner, remove restart loop, full integration & worker testsMotivation
Enables continuous in-place allocation profiling by wiring
SamplingHeapPrunerintoHeapProfilerand removing the JS stop/start restart loop that previously dropped surviving live samples on every collection window (fixes DataDog/dd-trace-js#11122).Changes
bindings/profilers/heap.{hh,cc},bindings/profilers/near-oom.{hh,cc}):HeapProfilerState::allocationsboolean withSamplingHeapPruner pruner(state->pruner.IsActive()as the single source of truth); callpruner.Reset()inStopSamplingHeapProfiler()and~HeapProfilerState().RestartSamplingHeapProfiler; addedUsesInPlacePruner.pruner.Start()(with raw double-start guard while active),pruner.BuildStats(),profile.reset(), andpruner.Prune()inGetAllocationProfile().NearHeapLimitto gate live-only filtering onstate->pruner.IsActive().ts/src/heap-profiler-bindings.ts,ts/src/heap-profiler.ts):restartSamplingHeapProfilerand thetry/finallyrestart loop; exportedusesInPlacePruner().isAllocationMode(),hasAllocationStats(), flattenedcollectProfile(), and synced mode on startup/runtime downgrade acrossv8Profile(),profile(),capture(), andconvertProfile().ts/test/test-heap-profiler.ts,ts/test/oom-heap-limit-extension.ts,ts/test/test-worker-threads.ts):profile()/capture()/v8Profile()/convertProfile(), empty trees, and mismatched root shapes.capture(), and Node version/platform startup guards.