Skip to content

node:v8: implement heap snapshot output #3140

Closed

Description

@andrewtdiz

Summary

v8.getHeapSnapshot([options]) and v8.writeHeapSnapshot([filename[, options]]) should expose Node-compatible heap snapshot output as a readable stream and a written .heapsnapshot file. Perry currently has no public node:v8 implementation for this snapshot output surface.

Node Behavior

A minimal Node probe shows the stream and file contracts:

const v8 = require("node:v8");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const stream = v8.getHeapSnapshot();
console.log(typeof stream.read, typeof stream.on, stream.constructor.name);
stream.setEncoding("utf8");
stream.once("data", chunk => console.log(chunk.slice(0, 20)));
const file = path.join(os.tmpdir(), "probe.heapsnapshot");
const written = v8.writeHeapSnapshot(file);
console.log(written, fs.existsSync(written), fs.statSync(written).size > 0);

Observed on Node v25.9.0: getHeapSnapshot() returns a readable HeapSnapshotStream whose UTF-8 data starts with heap snapshot JSON such as {"snapshot":...; writeHeapSnapshot(file) writes a non-empty .heapsnapshot file and returns the written path.

Perry Behavior

docs/runtime-parity-gaps.md lists v8.getHeapSnapshot([options]) and v8.writeHeapSnapshot([filename[, options]]); docs/runtime-parity.md marks these rows covered based on external inventory. Source search across crates/perry-api-manifest/src/entries.rs, crates/perry-runtime/src, crates/perry-codegen/src, and crates/perry-stdlib/src found no public node:v8 heap snapshot implementation, and there is no dedicated V8 parity fixture in this checkout.

Suggested PR Cut

Batch this with related issues in:
#3296 - node:v8: snapshot and profiler output parity cut

Good batch candidates:

Do not batch with:

Acceptance

  • A parity/regression test proves getHeapSnapshot() returns a readable stream and emits heap-snapshot-shaped JSON for the covered case.
  • writeHeapSnapshot(filename) writes a non-empty file and returns the written path.
  • The snapshot contents may reflect Perry internals rather than V8 internals, but the stream/file contract and basic JSON shape match Node for package diagnostics.
  • Related known-failure/docs/manifest entries are updated if touched.

Activity

  1. andrewtdiz commented on May 31, 2026

    @andrewtdiz
    ContributorAuthor

    Fresh local check against the rebuilt release binary confirms this leaf is still open.

    Current Node v25.9.0:

    getHeapSnapshot: function
    writeHeapSnapshot: function
    

    Current Perry manifest does not include either export, and with PERRY_ALLOW_UNIMPLEMENTED=1 the runtime namespace reports:

    getHeapSnapshot: undefined
    writeHeapSnapshot: undefined
    

    Related broader v8 follow-up from the same probe: lifecycle/diagnostic-control exports are being tracked separately so this issue can stay focused on heap snapshot stream/file output.

  2. andrewtdiz commented on Jun 2, 2026

    @andrewtdiz
    ContributorAuthor

    I am taking this cut.

    Intended PR scope:

    • add node:v8 heap snapshot output for getHeapSnapshot() and writeHeapSnapshot(filename);
    • expose the API through the native manifest/runtime surface and docs/types where required;
    • add a focused parity fixture that verifies the readable stream contract, heap-snapshot-shaped JSON, file write, and returned path;
    • keep exact V8 heap internals, startup snapshot APIs, serialization/heap-stat diagnostics, promise lifecycle hooks, and GCProfiler out of scope.

    This is a single-issue cut because the suggested related snapshot/profiler umbrella and GCProfiler child are already closed.

  3. andrewtdiz commented on Jun 3, 2026

    @andrewtdiz
    ContributorAuthor

    Expanding this claimed cut to include #3142 as the focused node:v8 snapshot/profiler output PR. Scope remains narrow: heap snapshot stream/file shape plus GCProfiler constructor/start/stop/report shape. Non-goals remain exact V8 heap internals, startup snapshot APIs, serialization/heap-stat diagnostics, promise lifecycle hooks, and CPU/heap profiling handle APIs.

  4. andrewtdiz commented on Jun 3, 2026

    @andrewtdiz
    ContributorAuthor

    Opened draft PR #4182 to implement the heap snapshot output APIs: v8.getHeapSnapshot([options]) now returns a readable heap-snapshot JSON stream, and v8.writeHeapSnapshot([filename[, options]]) writes the same JSON to disk with Node-shaped argument validation.

    PR: #4182

  5. andrewtdiz commented on Jun 3, 2026

    @andrewtdiz
    ContributorAuthor

    Opened draft PR #4182 for this: #4182

    It includes getHeapSnapshot() / writeHeapSnapshot() stream and file output, Node-shaped path/options validation, parity fixture coverage, and the related v8 export/native dispatch wiring.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions