Skip to content

[2/4] feat(heap): add watermarked allocation stats and live-only near-OOM filtering - #460

Open
IlyasShabi wants to merge 1 commit into
ishabi/heap-pruner-1-lifecycle-perffrom
ishabi/heap-pruner-2-watermark-oom
Open

IlyasShabi wants to merge 1 commit into
ishabi/heap-pruner-1-lifecycle-perffrom
ishabi/heap-pruner-2-watermark-oom

Conversation

@IlyasShabi

@IlyasShabi IlyasShabi commented Dec 2, 2026 •

Copy link
Copy Markdown

Stack

# PR Base Summary
1 #459 main Lifecycle hardening, translation fast paths, and OOM callback correctness
2 #460 ← this PR ishabi/heap-pruner-1-lifecycle-perf Watermarked BuildAllocationStatsByNodeId and live-only near-OOM filtering
3 #461 ishabi/heap-pruner-2-watermark-oom Self-contained SamplingHeapPruner implementation + design doc
4 #462 ishabi/heap-pruner-3-sampling-pruner Wire SamplingHeapPruner, remove restart loop, full integration & worker tests

Motivation

Introduces the pure-C++ sample watermarking and live-only filtering primitives needed for continuous allocation profiling and accurate near-OOM reporting (DataDog/dd-trace-js#11122).

Changes

  • Watermarked stats (bindings/allocation-profile.{hh,cc}):
    • Extended BuildAllocationStatsByNodeId with optional sample_id_watermark, dead_count, and live_only parameters:
      • Live samples always contribute to inuse_*; only samples with sample_id > watermark contribute to alloc_* (preventing double-counting surviving live objects across windows).
      • Tracks *dead_count and advances *sample_id_watermark monotonically without regression.
      • live_only = true omits dead-only nodes and buckets directly.
  • Live-only near-OOM filtering (bindings/translate-heap-profile.{hh,cc}, bindings/profilers/near-oom.cc):
    • Extended TranslateAllocationProfileToCpp with optional const AllocationProfileNodeStatsMap* live_stats to emit only inuse_objects > 0 buckets sorted by size and prune dead subtrees (while always keeping root non-null).
    • Updated NearHeapLimit on Node 26+ in allocation mode to filter out dead samples via BuildAllocationStatsByNodeId(..., /*live_only=*/true) before dumping/exporting/invoking OOM callbacks.
  • Tests (bindings/test/binding.cc, ts/test/oom-heap-limit-extension.ts, ts/test/test-heap-profiler.ts):
    • Added TestBuildAllocationStatsWithWatermark covering all 4 (is_live, sample_id > watermark) quadrants, multi-window advancement, non-regression, sample_id == watermark boundary, 64-bit byte math, and live_only.
    • Updated OOM allocation tests to allocate & GC dead short-lived churn (deadShortLivedChurn) and assert it is excluded from stderr dumps and Async/Interrupt OOM callbacks.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Overall package size

Self size: 2.82 MB
Deduped: 3.95 MB
No deduping: 3.95 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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/apm-reliability/pprof-nodejs | benchmarks-pr-comment

View more details · View in GitLab

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 508356e | Docs | View more details | Give us feedback!

@IlyasShabi
IlyasShabi marked this pull request as ready for review December 2, 2026 14:43

@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.

LGTM, just one little nit, but not critical.

);
if (allocations) heap.profile();
if (allocations) {
let warm = new Array<number>(CHUNK_SIZE / 8).fill(1.5);

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.

The new tests only assert that deadShortLivedChurn is absent from the OOM profile. If the churn is ever not sampled, they'd pass even with the live-only filter broken. Could we add a positive check first, e.g. heap.v8Profile() after the churn showing it with allocSpaceBytes > 0?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants