Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/jsc/bindings/BunHeapProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ WTF::String generateHeapSnapshotV8(JSC::VM& vm)
{
vm.ensureHeapProfiler();
auto& heapProfiler = *vm.heapProfiler();
heapProfiler.clearSnapshots();

JSC::BunV8HeapSnapshotBuilder builder(heapProfiler);
return builder.json();
Expand Down
1 change: 0 additions & 1 deletion src/jsc/bindings/BunObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,8 @@
JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshot, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = JSC::getVM(globalObject);
vm.ensureHeapProfiler();
auto& heapProfiler = *vm.heapProfiler();

Check warning on line 780 in src/jsc/bindings/BunObject.cpp

View check run for this annotation

Claude / Claude Code Review

HeapProfiler snapshot chain grows unboundedly after removing clearSnapshots()

Removing `clearSnapshots()` means `HeapProfiler::m_snapshots` now grows by one entry per snapshot for the life of the VM, and every subsequent GC's `removeDeadHeapSnapshotNodes` (plus `sweepCell`/`shrinkToFit`/`nodeForCell`) recurses the full `m_previous` chain — so per-GC overhead and container memory scale O(N) with snapshots taken. The PR description's "delta storage bounds growth" only covers node storage, not the chain itself. Retaining the chain is required for id stability so this shouldn
Comment thread
robobun marked this conversation as resolved.
Resolved
heapProfiler.clearSnapshots();

Bun__Feature__heap_snapshot += 1;

Expand Down
1 change: 0 additions & 1 deletion src/jsc/bindings/webcore/JSWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ static inline JSC::EncodedJSValue jsWorkerPrototypeFunction_getHeapSnapshotBody(
auto& vm = workerCtx.vm();
vm.ensureHeapProfiler();
auto& heapProfiler = *vm.heapProfiler();
heapProfiler.clearSnapshots();
JSC::BunV8HeapSnapshotBuilder builder(heapProfiler);
String snapshot = builder.json();

Expand Down
45 changes: 45 additions & 0 deletions test/js/bun/util/v8-heap-snapshot-fixture.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/js/bun/util/v8-heap-snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ test("v8.writeHeapSnapshot() with path", async () => {
expect(await runFixture("write-path", { args: [path] })).toEqual({ returnedPath: path, ...structure });
});

test("v8 heap snapshot node ids are stable across snapshots", async () => {
const { id1, id2, found, stable } = await runFixture("id-stability");
expect({ found, stable, id1, id2 }).toEqual({ found: true, stable: true, id1, id2: id1 });
});

test("v8 heap snapshot labels Web Streams internal edges", async () => {
const edges = await runFixture("stream-edges");
// Every WriteBarrier member reported by analyzeHeap shows up as a named
Expand Down
Loading