Skip to content

src: allow building the snapshot on top of a V8 startup blob - #65374

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:embedder/snapshot-base-blob
Open

src: allow building the snapshot on top of a V8 startup blob#65374
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:embedder/snapshot-base-blob

Conversation

@codebytere

@codebytere codebytere commented Aug 18, 2026

Copy link
Copy Markdown
Member

CommonEnvironmentSetup::CreateForSnapshotting() always creates the SnapshotCreator without a startup blob, so V8 sets its heap up from scratch. An embedder whose V8 is built with external startup data (Chromium-style: only the deserializer is linked in) can't do that at all, so node_mksnapshot and the embedder snapshot API are unusable there without patching Node; and even where it works, a from-scratch snapshot sits on a different read-only-heap lineage than the isolates the embedder creates from its own blob, which V8's shared RO heap doesn't allow in one process.

This adds SnapshotConfig::base_blob, an optional caller-owned v8::StartupData that is passed to the SnapshotCreator (CreateParams::snapshot_blob), so V8 deserializes its heap from that blob and Node adds its isolate data and contexts on top - the same way Blink's context snapshot is produced. node_mksnapshot grows --v8-snapshot-blob=<file> for hosts that build Node against such a V8. Node's own build never sets it and is unchanged; consuming a snapshot built this way needs no changes (EmbedderSnapshotData / Context::FromSnapshot as today).

Contract, documented on the field: the blob is a plain V8 startup blob (what mksnapshot emits), must outlive the setup, and the result loads only into a process on the same RO lineage - the rule V8 already imposes.

embedtest gets --create-v8-startup-blob <file> (a SnapshotCreator with just a default context) and --embedder-snapshot-base-blob <file>; the new test builds a plain blob, builds the embedder snapshot on top of it, and round-trips argv through the result like test-embedding-snapshot-as-file does.

Tests: new test-embedding-snapshot-base-blob.js; embedding suite and cctest pass. Locally I also generated node_snapshot.cc with node_mksnapshot --v8-snapshot-blob=<plain blob>, linked node against it and ran the snapshot/process/worker/vm/bootstrap suites on that binary: all pass.


Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.

CommonEnvironmentSetup::CreateForSnapshotting() always created the
SnapshotCreator without a startup blob, so V8 set up its heap from
scratch. That is impossible when the V8 that Node.js is linked against
only carries the deserializer (external startup data, as Chromium builds
it), and it puts the resulting snapshot on a different read-only heap
lineage than isolates the embedder creates from its own blob. Embedders
in that situation cannot use the snapshot support at all today.

Add SnapshotConfig::base_blob, an optional caller-owned v8::StartupData
that is handed to the SnapshotCreator so that V8 deserializes its heap
from that blob and Node.js adds its isolate data and contexts on top,
the way Blink's context snapshot is built. node_mksnapshot accepts
--v8-snapshot-blob=<file> for hosts that build Node.js with such a V8;
Node.js's own build never passes it and is unchanged. Consuming the
result needs no changes.

embedtest can create a plain V8 startup blob and build the embedder
snapshot on top of one, and a test round-trips argv through a snapshot
built that way.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Aug 18, 2026
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.12%. Comparing base (30bff4a) to head (99bfd98).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/api/embed_helpers.cc 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65374      +/-   ##
==========================================
- Coverage   90.13%   90.12%   -0.02%     
==========================================
  Files         752      752              
  Lines      251568   251865     +297     
  Branches    47270    47364      +94     
==========================================
+ Hits       226759   226988     +229     
- Misses      16168    16186      +18     
- Partials     8641     8691      +50     
Files with missing lines Coverage Δ
src/node.h 92.45% <100.00%> (+0.14%) ⬆️
src/api/embed_helpers.cc 75.00% <66.66%> (-0.13%) ⬇️

... and 59 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codebytere codebytere added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants