function

generateHeapSnapshot

format?: 'jsc'

Generates a heap snapshot in JavaScriptCore's format. View it with bun --inspect or Safari's Web Inspector

format: 'v8'
): string;

Generates a V8 heap snapshot for use with Chrome DevTools or Visual Studio Code

Returns a JSON string you can save to a file.

const snapshot = Bun.generateHeapSnapshot("v8");
await Bun.write("heap.heapsnapshot", snapshot);
format: 'v8',
encoding: 'arraybuffer'

Generates a V8 heap snapshot as an ArrayBuffer containing the UTF-8 encoded JSON.

This avoids the overhead of creating a JavaScript string for large heap snapshots.

const snapshot = Bun.generateHeapSnapshot("v8", "arraybuffer");
await Bun.write("heap.heapsnapshot", snapshot);

Referenced types

interface HeapSnapshot

JavaScriptCore engine's internal heap snapshot format

For a snapshot Chrome DevTools can read, use generateHeapSnapshot with the "v8" format.

class ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

  • readonly [Symbol.toStringTag]: string
  • readonly byteLength: number

    Read-only. The length of the ArrayBuffer (in bytes).

  • newByteLength?: number
    ): void;

    Resizes the ArrayBuffer to the specified size (in bytes).

    MDN

    byteLength: number

    Resize an ArrayBuffer in-place.

  • begin: number,
    end?: number

    Returns a section of an ArrayBuffer.

  • newByteLength?: number

    Creates a new ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN

  • newByteLength?: number

    Creates a new non-resizable ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN