Skip to content

Bump WebKit: align V8 heap snapshot output with Chrome DevTools expectations - #29557

Closed
Jarred-Sumner wants to merge 6 commits into
mainfrom
jarred/webkit-ce78f86
Closed

Jarred-Sumner wants to merge 6 commits into
mainfrom
jarred/webkit-ce78f86

Conversation

@Jarred-Sumner

@Jarred-Sumner Jarred-Sumner commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Bumps WebKit to b173a72ad722 — four commits to BunV8HeapSnapshotBuilder that bring the .heapsnapshot output into line with what Chrome DevTools actually parses, found by auditing against V8's heap-snapshot-generator.cc.

Why

Bun's v8.writeHeapSnapshot() and the inspector's HeapProfiler.takeHeapSnapshot produce a V8-format JSON file. DevTools is the only real consumer of that format and it makes a lot of structural assumptions that aren't in any spec — node-type semantics drive shallow-size attribution, the system / name prefix drives styling, root topology drives the Distance column, and node IDs drive snapshot diffing. Several of those assumptions were silently violated, so snapshots loaded but showed misleading data.

User-visible fixes in DevTools

Symptom before Cause Fix
Every JS Array shows 0 shallow size; bytes reattributed to whatever references it We emitted kArray, which V8 reserves for internal FixedArray backing stores; DevTools' calculateShallowSizes() zeroes those and reassigns JSArray → kObject, name "Array"
Arrays don't appear in the Statistics pie chart "JS arrays" bucket; Summary fragments by length Name was "Array (123)"; DevTools matches kObject && rawName()==='Array' exactly Name is now the constructor name
Lexical environments / module scopes show as compiled code kCode for LexicalEnvironment, ModuleEnvironment, WithScope, etc. kObject with "system / <ClassName>" names — DevTools greys them out as internals while still showing them in retainer chains. Captured variables continue to render as named children via the existing analyzeVariableNameEdge path
Retainers view shows GC roots as "<varname> in system / Context" with an empty varname, as if a closure were retaining the object ConservativeScan, StrongHandles, JITStubRoutines etc. were emitted as kContextVariable edges, which V8 reserves strictly for closure-captured locals Those root edges are now kInternal
Promises fragment across many Summary rows: Promise (pending), Promise (fulfilled: Object), Promise (rejected)… Name embedded status + recursed into the fulfilled value Name is just "Promise"; status/result are visible by expanding the node's properties like in V8
Distance column shows 1 for everything Root referenced objects directly with no (GC roots) intermediary and no shortcut edge to the global; DevTools' BFS couldn't distinguish user roots from system roots Added a synthetic (GC roots) node; from==nullptr edges route through it; each JSGlobalObject gets a root → shortcut → global edge
Snapshot diff and "Objects allocated between A and B" return garbage Node IDs were a 24-bit pointer hash (birthday-collides at ~5k objects) and weren't stable across snapshots IDs now come from JSC's HeapProfiler HeapSnapshot chain — same cell keeps the same ID across snapshots, new cells get monotone-increasing IDs from the shared getNextObjectIdentifier() counter, and Heap::removeDeadHeapSnapshotNodes prunes dead entries via forEachDeadCell on every GC so address reuse doesn't alias
Long strings bloat the snapshot file No truncation Strings capped at 1024 chars (V8's --heap-snapshot-string-limit default), no ellipsis, dedup on truncated content
Taking a snapshot of a heap with large rope strings was slow Ropes were resolved to flat strings just to get the node name Ropes >16K chars are named "(concatenated string)"; smaller ropes are resolved so the first 1024 chars show as the node name

Correctness / robustness fixes

  • analyzeNode TOCTOU under parallel marking: the old check-m_cellToNodeId-then-release-then-insert sequence let two GC marking threads each append a Node for the same cell. analyzeNode now just calls getOrCreateNodeId, which holds m_cellToNodeIdMutex across the entire find-or-insert.
  • JSON key order: trace_tree is now emitted immediately after trace_function_infos (before samples/locations) to match V8's serializer. DevTools' streaming loader is positional once trace_function_count > 0; we hard-code 0 today so this was latent, but it's a one-line landmine to leave in.
  • ShadowRealm, WebAssembly.Module, WebAssembly.Instance are now kObject (were kCode).

Cost

The cross-snapshot ID chain pins ~16 bytes per live object ({JSCell*, unsigned}) in HeapProfiler for the duration of the profiling session — same footprint as V8's HeapObjectsMap. Each cell lives in exactly one snapshot in the chain (the one where it first appeared) and dead entries are swept on every GC, so the bound is live-object count, not objects-ever-seen. One-off v8.writeHeapSnapshot() calls pay this until the HeapProfiler is torn down.

Commits

Full range: oven-sh/WebKit@4d5e75e...b173a72

CI will fail until the WebKit autobuild-b173a72ad7225e0ef7ab2c8724025caac2665336 release artifacts are published.

Truncates long strings in V8 heap snapshots to 1024 chars to match V8's
--heap-snapshot-string-limit default, keeping snapshot files bounded when
the heap contains very large strings.

oven-sh/WebKit@4d5e75e...ce78f86
@robobun

robobun commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator
Updated 4:31 PM PT - Apr 21st, 2026

❌ @Jarred-Sumner, your commit afa6708 has 3 failures in Build #46963 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 29557

That installs a local version of the PR into your bun-29557 executable, so you can run:

bun-29557 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 1 issue this PR may fix:

  1. getHeapSnapshot causes lodestar beacon node to crash #23393 - v8.getHeapSnapshot() crashes on large applications; truncating long strings in the snapshot builder reduces memory pressure during serialization, likely preventing the crash

If this is helpful, copy the block below into the PR description to auto-close this issue on merge.

Fixes #23393

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Bumped the vendored WebKit revision constant and changed decorator tests to run concurrently in the test runner.

Changes

Cohort / File(s) Summary
WebKit version constant
scripts/build/deps/webkit.ts
Updated exported WEBKIT_VERSION constant from 4d5e75ebd84a14edbc7ae264245dcd77fe597c10 → c1fc04865a915e0ef7ab2c8724025caac2665336, which changes derived prebuilt download tag/hash and extraction directory prefix behavior.
Decorator tests — concurrency
test/bundler/transpiler/es-decorators-esbuild.test.ts
Converted non-todo test cases to test.concurrent(...) so decorator tests are scheduled to run in parallel; test internals and assertions unchanged.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly reflects the main change: bumping WebKit and aligning heap snapshot output with V8/Chrome DevTools expectations, which is the core objective of this PR.
Description check ✅ Passed The PR description is comprehensive and thorough, covering the motivation, user-visible fixes, correctness improvements, and cost analysis.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/build/deps/webkit.ts`:
- Line 6: The WEBKIT_VERSION constant in scripts/build/deps/webkit.ts was
changed to "ce78f86a3ec34a178a672250e9045e807811eb7e" which maps to a
non-existent prebuilt tag (autobuild-ce78f86a3ec34a178a672250e9045e807811eb7e);
fix by either reverting WEBKIT_VERSION back to the last known-good hash in
scripts/build/deps/webkit.ts or ensure the matching release and its prebuilt
assets are published in oven-sh/WebKit before merging so CI can download the
prebuilt binary (reference the WEBKIT_VERSION symbol to locate the change).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6b8ac536-97df-47fa-a1a1-805ff0d6487e

📥 Commits

Reviewing files that changed from the base of the PR and between f32e595 and 9d05355.

📒 Files selected for processing (1)
  • scripts/build/deps/webkit.ts

Comment thread scripts/build/deps/webkit.ts Outdated
* From https://github.com/oven-sh/WebKit releases.
*/
export const WEBKIT_VERSION = "4d5e75ebd84a14edbc7ae264245dcd77fe597c10";
export const WEBKIT_VERSION = "ce78f86a3ec34a178a672250e9045e807811eb7e";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

TAG="autobuild-ce78f86a3ec34a178a672250e9045e807811eb7e"
API="https://api.github.com/repos/oven-sh/WebKit/releases/tags/${TAG}"

echo "Checking ${API}"
curl -fsSL "${API}" | jq -r '
  "tag=\(.tag_name)",
  "published_at=\(.published_at)",
  "asset_count=\(.assets | length)",
  "assets:",
  (.assets[]?.name // empty)
'

Repository: oven-sh/bun

Length of output: 239


Release assets must be published before merge—prebuilt tag does not exist.

Line 6 updates the hash to ce78f86a3ec34a178a672250e9045e807811eb7e, which derives the prebuilt download tag autobuild-ce78f86a3ec34a178a672250e9045e807811eb7e. This release tag does not exist in oven-sh/WebKit (verified via GitHub API), so CI and all build systems will fail to fetch the prebuilt binary post-merge. Either publish the release with assets before merge, or revert this change.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/build/deps/webkit.ts` at line 6, The WEBKIT_VERSION constant in
scripts/build/deps/webkit.ts was changed to
"ce78f86a3ec34a178a672250e9045e807811eb7e" which maps to a non-existent prebuilt
tag (autobuild-ce78f86a3ec34a178a672250e9045e807811eb7e); fix by either
reverting WEBKIT_VERSION back to the last known-good hash in
scripts/build/deps/webkit.ts or ensure the matching release and its prebuilt
assets are published in oven-sh/WebKit before merging so CI can download the
prebuilt binary (reference the WEBKIT_VERSION symbol to locate the change).

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — routine WebKit version bump.

Extended reasoning...

Overview

This PR changes a single line in scripts/build/deps/webkit.ts, updating the WEBKIT_VERSION constant from 4d5e75ebd84a... to ce78f86a3ec3.... This constant determines which prebuilt WebKit tarball is downloaded (or which commit is checked out in local mode). The actual behavioral change (string truncation in BunV8HeapSnapshotBuilder) lives in the oven-sh/WebKit repo and is not part of this diff.

Security risks

None in this diff. It is a hash constant pointing at a commit in Bun's own WebKit fork, consumed by the existing prebuilt-download / local-checkout machinery. No new code paths, no user-controlled input, no auth/crypto/permissions surface.

Level of scrutiny

Low. This is a mechanical dependency version bump following the established pattern documented at the top of the file. The only thing that could go wrong is the artifact not existing yet, which the PR description already calls out (CI will fail until the autobuild release is published) — that is self-correcting via CI.

Other factors

No CODEOWNERS entry covers this file. No prior reviewer comments to address. The bug-hunting system found no issues. The change is a single-line constant swap with clear intent and a detailed PR description linking the upstream diff.

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. Fix segfault in generateHeapSnapshot('v8') with large strings in heap #29389 - Fixes the same V8 heap snapshot large-string crash in BunV8HeapSnapshotBuilder by capping string names at 1024 characters, applied on the Bun side rather than via a WebKit bump

🤖 Generated with Claude Code

Align V8 heap snapshot node/edge classification and JSON layout with V8:
JSArray as kObject (was kArray, which made DevTools zero its shallow size),
scopes as kObject with "system / " names, GC-root edges as kInternal,
Promise/Array node names use constructor name for proper Summary grouping,
ropes named "(concatenated string)", and trace_tree ordered before
samples/locations.
@Jarred-Sumner Jarred-Sumner changed the title Bump WebKit: truncate long strings in V8 heap snapshots Bump WebKit: align V8 heap snapshot output with V8 Apr 21, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — routine WebKit version bump; the bun-side change is a single hash constant and the upstream JSC changes are well-documented in the description.

Extended reasoning...

Overview

This PR changes exactly one line in scripts/build/deps/webkit.ts: the WEBKIT_VERSION constant is bumped from 4d5e75ebd84a to c9f26a68b86c. All substantive behavioral changes (V8 heap snapshot builder fixes) live in the oven-sh/WebKit fork, not in this repo. The PR description gives a thorough breakdown of what changed upstream.

Security risks

None in the bun-side diff — it is a hash constant update with no logic, parsing, auth, or user-input handling. The referenced WebKit changes affect heap-snapshot serialization (node type/name classification, string truncation, JSON key ordering) which is a debugging/diagnostics surface, not a security boundary.

Level of scrutiny

Low for the bun repo change itself. WebKit version bumps are a well-established, frequently-exercised pattern here (the two most recent commits on main are both WebKit bumps, including one to this exact hash). The build system treats WEBKIT_VERSION purely as a download-tag/checkout identifier; there is no conditional logic keyed off the value. Review of the actual JSC code belongs on the WebKit side, and the author has clearly already done that comparison work against V8's heap-snapshot-generator.cc.

Other factors

  • CI is currently red, but the author explicitly notes this is expected until the autobuild-c9f26a68b86c… release artifacts finish publishing — this is the normal sequencing for WebKit bumps and CI acts as the gate.
  • CodeRabbit's "tag does not exist" warning references a stale intermediate hash (ce78f86a3ec3), not the final one in this diff, and is moot once artifacts publish.
  • No bugs were found by the bug-hunting system.
  • A bot flagged possible overlap with #29389; that's a coordination question for the author, not a correctness issue with this one-line change.

Sequential collision-free node IDs (was 24-bit hash), synthetic (GC roots)
subtree + root→shortcut→global so DevTools' Distance column works, and fix
the analyzeNode TOCTOU that could create duplicate nodes under parallel
marking.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
scripts/build/deps/webkit.ts (1)

6-6: ⚠️ Potential issue | 🔴 Critical

Release artifacts must be published before merge—this is a known blocker.

The updated hash 59188212cf11248f0cd3578b62207664c4f7adbd derives the prebuilt download tag autobuild-59188212cf11248f0cd3578b62207664c4f7adbd. As noted in the PR objectives, CI will fail until WebKit autobuild release artifacts for this commit are published in oven-sh/WebKit. The bot has already reported build failures across multiple platforms (Build #46921).

This must be resolved before merge by publishing the release with all required platform assets.

Run the following script to verify the release status:

#!/bin/bash
set -euo pipefail

TAG="autobuild-59188212cf11248f0cd3578b62207664c4f7adbd"
API="https://api.github.com/repos/oven-sh/WebKit/releases/tags/${TAG}"

echo "Checking release: ${TAG}"
curl -fsSL "${API}" | jq -r '
  if .message == "Not Found" then
    "❌ Release does not exist"
  else
    "✅ Release exists:",
    "  Published: \(.published_at)",
    "  Assets: \(.assets | length)",
    "  Asset names:",
    (.assets[]?.name // empty)
  end
' || echo "❌ Release tag not found (HTTP 404)"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/build/deps/webkit.ts` at line 6, The WEBKIT_VERSION constant in
scripts/build/deps/webkit.ts was updated to
"59188212cf11248f0cd3578b62207664c4f7adbd", which requires a corresponding
published GitHub release with tag
autobuild-59188212cf11248f0cd3578b62207664c4f7adbd containing all prebuilt
platform assets; publish that release (with all required platform assets) to
oven-sh/WebKit, then verify the release exists and assets are present (use the
provided script or GitHub API) before merging so CI will pass, and only then
keep the new WEBKIT_VERSION value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@scripts/build/deps/webkit.ts`:
- Line 6: The WEBKIT_VERSION constant in scripts/build/deps/webkit.ts was
updated to "59188212cf11248f0cd3578b62207664c4f7adbd", which requires a
corresponding published GitHub release with tag
autobuild-59188212cf11248f0cd3578b62207664c4f7adbd containing all prebuilt
platform assets; publish that release (with all required platform assets) to
oven-sh/WebKit, then verify the release exists and assets are present (use the
provided script or GitHub API) before merging so CI will pass, and only then
keep the new WEBKIT_VERSION value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2fa44dbf-5bc6-4a37-b52a-f9da686c6e5e

📥 Commits

Reviewing files that changed from the base of the PR and between 3484e4f and 3158180.

📒 Files selected for processing (1)
  • scripts/build/deps/webkit.ts

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — routine WebKit version bump following the established pattern; substantive changes live in oven-sh/WebKit.

Extended reasoning...

Overview

This PR changes a single line in scripts/build/deps/webkit.ts, updating the WEBKIT_VERSION constant from 4d5e75ebd84a to 59188212cf11. The constant determines which prebuilt WebKit tarball is downloaded (or which commit is checked out in local mode). All substantive code changes — the BunV8HeapSnapshotBuilder fixes for node/edge classification, sequential node IDs, the (GC roots) subtree, the TOCTOU fix, and JSON key ordering — live in the oven-sh/WebKit repo and are not part of this diff.

Security risks

None in this diff. The change is a hardcoded commit hash pointing to the project's own WebKit fork; no user input, no URL construction changes, no auth/crypto/permissions code touched. The upstream heap-snapshot changes are diagnostic-output formatting and don't expand attack surface.

Level of scrutiny

Low for the bun-side diff: this is a mechanical version bump matching an established pattern (the recent commit history shows three consecutive WebKit bumps of identical shape). The real review surface is the WebKit-side diff, which is out of scope for this repo and would be reviewed in oven-sh/WebKit's own PR process. CI acts as the gate here — the author explicitly noted that builds will fail until the autobuild-59188212cf11... release artifacts are published, so there's no risk of a silent bad merge.

Other factors

  • CodeRabbit flagged a missing release tag, but that was for an intermediate hash and the author already acknowledged the artifacts caveat in the description.
  • The bug-hunting system found no issues.
  • No prior reviews from me on this PR.
  • The PR description is unusually thorough, documenting each upstream change and known limitations (cross-snapshot ID stability), which gives confidence the author understands the impact.

Persist V8 heap snapshot node IDs across snapshots via HeapProfiler's
HeapSnapshot chain so DevTools' "Objects allocated between A and B" filter
and snapshot diffing work.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — routine WebKit hash bump plus a test-only concurrency tweak.

Extended reasoning...

Overview

This PR touches two files with one-line changes each: scripts/build/deps/webkit.ts updates the WEBKIT_VERSION constant to a new oven-sh/WebKit commit hash, and test/bundler/transpiler/es-decorators-esbuild.test.ts switches the generated tests from test(...) to test.concurrent(...). The substantive heap-snapshot changes described in the PR body live in the WebKit repo, not in this diff.

Security risks

None. The version-bump line only changes which prebuilt tarball/tag is fetched from the trusted oven-sh/WebKit releases; no new URLs, auth, or input handling are introduced. The test change is test-infrastructure only.

Level of scrutiny

Low. WebKit hash bumps are a routine, mechanical pattern in this repo (see recent commits doing the same), and correctness is gated by CI once the autobuild artifacts publish — which the PR description already calls out, so the CodeRabbit warning about the missing release tag is expected and acknowledged. The test.concurrent change is safe: each iteration creates its own tempDir and spawns an isolated subprocess, so there is no shared mutable state between tests.

Other factors

No bugs were found by the bug-hunting system, and there are no outstanding human reviewer comments. The diff is minimal and follows established patterns, so human review adds little value here.

@Jarred-Sumner Jarred-Sumner changed the title Bump WebKit: align V8 heap snapshot output with V8 Bump WebKit: align V8 heap snapshot output with Chrome DevTools expectations Apr 21, 2026
Comment thread scripts/build/deps/webkit.ts Outdated
* From https://github.com/oven-sh/WebKit releases.
*/
export const WEBKIT_VERSION = "4d5e75ebd84a14edbc7ae264245dcd77fe597c10";
export const WEBKIT_VERSION = "c1fc04865a915e0ef7ab2c8724025caac2665336";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 The Bun-side callers still call heapProfiler.clearSnapshots() immediately before constructing BunV8HeapSnapshotBuilder (BunHeapProfiler.cpp:943, BunObject.cpp:811, JSWorker.cpp:696), which wipes the HeapProfiler chain so mostRecentSnapshot() is always null and IDs restart from scratch on every call — defeating the cross-snapshot ID stability this bump advertises. Worse, since the builder now appendSnapshot()s, Bun pays the ~16B/live-object retention cost between calls while getting none of the diffing benefit; the clearSnapshots() calls on the V8-builder paths should be dropped as part of landing this bump.

Extended reasoning...

What the bug is

This WebKit bump's headline structural change is cross-snapshot node-ID stability: the new BunV8HeapSnapshotBuilder constructor reads m_previousSnapshot = profiler.mostRecentSnapshot(), analyzeNodeInternal() reuses an existing identifier via m_previousSnapshot->nodeForCell(cell), and json()/jsonBytes() call m_profiler.appendSnapshot(...) so the next snapshot can chain off this one. The WebKit diff explicitly removed the internal m_profiler.clearSnapshots() that used to sit at the top of json()/jsonBytes() precisely to enable this chaining.

However, all three Bun-side call sites that construct the V8 builder still call heapProfiler.clearSnapshots() immediately before constructing it:

  • src/bun.js/bindings/BunHeapProfiler.cpp:943 (generateHeapSnapshotV8 → v8.writeHeapSnapshot / v8.getHeapSnapshot)
  • src/bun.js/bindings/BunObject.cpp:811 (Bun.generateHeapSnapshot)
  • src/bun.js/bindings/webcore/JSWorker.cpp:696 (worker.getHeapSnapshot)

HeapProfiler::clearSnapshots() does m_snapshots.clear(), which empties exactly the chain the new builder relies on.

Step-by-step proof

  1. User calls v8.getHeapSnapshot() → generateHeapSnapshotV8(vm).
  2. Line 943: heapProfiler.clearSnapshots() → m_snapshots is now empty.
  3. Line 945: BunV8HeapSnapshotBuilder builder(heapProfiler) → ctor sets m_previousSnapshot = profiler.mostRecentSnapshot() = nullptr (vector is empty).
  4. During analyzeNodeInternal, the m_previousSnapshot->nodeForCell(cell) reuse path is skipped for every cell; each gets a fresh getNextObjectIdentifier().
  5. builder.json() runs m_profiler.appendSnapshot(...) → snapshot A is now retained in HeapProfiler (~16 B per live object).
  6. User calls v8.getHeapSnapshot() again.
  7. Line 943: heapProfiler.clearSnapshots() → snapshot A is destroyed before the new builder can read it.
  8. New builder again sees m_previousSnapshot == nullptr, assigns brand-new IDs to the same surviving JSCells.

So the same object gets different IDs in snapshot A vs B, and DevTools' "Objects allocated between Snapshot A and B" / comparison view cannot correlate them — exactly the feature the PR description says is now enabled.

Why existing code doesn't prevent it

These clearSnapshots() calls were correct (or at least harmless) before this bump, because the old builder cleared snapshots internally anyway and used a 24-bit pointer hash for IDs. They were not updated when the WebKit-side semantics changed in c1fc04865a91, and this PR only bumps the hash without touching the Bun callers.

Impact

  • Feature dead-on-arrival: the advertised cross-snapshot diffing / "allocated between A and B" filter will not work via any of Bun's public entry points (v8.getHeapSnapshot, v8.writeHeapSnapshot, Bun.generateHeapSnapshot('v8'), worker.getHeapSnapshot()).
  • Memory regression with no upside: because appendSnapshot() now retains the snapshot in HeapProfiler, Bun holds ~16 bytes per live object from the end of one snapshot call until the start of the next clearSnapshots(). Previously the snapshot was freed when json() returned. So the bump adds the retention cost while the upfront clear throws away the only benefit.

Fix

Drop the heapProfiler.clearSnapshots() calls on the three V8-builder code paths (leave the one at BunHeapProfiler.cpp:118 for the JSC GCDebuggingSnapshot path alone — that's a different builder). If an explicit reset is desired, expose it as a separate user-facing API rather than wiping on every call.

@robobun

robobun commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded. The BunV8HeapSnapshotBuilder commits this bump carries (ce78f86a3ec3, c9f26a68b86c, 59188212cf11, c1fc04865a91, b173a72ad722) were already on the fork's main line and shipped in Bun with the 87fd0daba19a upgrade (#29393, merged 2026-04-25). Main's current pin, 7b763944 (#37525), still contains all of them, and the only later changes to the builder were upstream-merge build fixes. The test.concurrent change to es-decorators-esbuild.test.ts landed separately in #29534, and that file has since been reworked to run all cases from a single spawn (#30875).

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