function
bun.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
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.