Node.js module
v8
The 'node:v8' module exposes APIs for heap snapshots and memory profiling. In Node.js these are V8-specific; Bun provides compatible implementations using JavaScriptCore.
Methods include v8.getHeapSnapshot(), v8.writeHeapSnapshot(), and v8.takeHeapSnapshot().
Works in Bun · notes
`writeHeapSnapshot` and `getHeapSnapshot` are implemented. `serialize` and `deserialize` use JavaScriptCore's wire format, not V8's. Most other V8-specific methods are not implemented. For profiling, consider using `bun:jsc`.
Functions 17
- v8.cachedDataVersionTag()
Returns an integer representing a version tag derived from the V8 version, command-line flags, and detected CPU features.
- v8.deserialize()
Uses a
DefaultDeserializerwith default options to read a JS value from a buffer. - v8.getCppHeapStatistics()
It returns an object with a structure similar to the
cppgc::HeapStatisticsobject. - v8.getHeapCodeStatistics()
Get statistics about code and its metadata in the heap, see
- v8.getHeapSnapshot()
Generates a snapshot of the current V8 heap and returns a Readable
- v8.getHeapSpaceStatistics()
Returns statistics about the V8 heap spaces, i.e.
- v8.getHeapStatistics()
Returns an object with the following properties.
- v8.isStringOneByteRepresentation()
V8 only supports
Latin-1/ISO-8859-1andUTF16as the underlying representation of a string. - v8.queryObjects()
This is similar to the
queryObjects()console API provided by the Chromium DevTools console. - v8.serialize()
Uses a
DefaultSerializerto serializevalueinto a buffer. - v8.setFlagsFromString()
The
v8.setFlagsFromString()method can be used to programmatically set - v8.setHeapSnapshotNearHeapLimit()
The API is a no-op if
--heapsnapshot-near-heap-limitis already set from the command line or the API is called more than once. - v8.startCpuProfile()
Starting a CPU profile then return a
SyncCPUProfileHandleobject. - v8.startHeapProfile()
Starting a heap profile then return a
SyncHeapProfileHandleobject. - v8.stopCoverage()
The
v8.stopCoverage()method allows the user to stop the coverage collection started byNODE_V8_COVERAGE, so that V8 can release the execution count records and op… - v8.takeCoverage()
The
v8.takeCoverage()method allows the user to write the coverage started byNODE_V8_COVERAGEto disk on demand. - v8.writeHeapSnapshot()
Generates a snapshot of the current V8 heap and writes it to a JSON file.
Classes 5
- class v8.DefaultDeserializer
A subclass of
Deserializercorresponding to the format written byDefaultSerializer. - class v8.DefaultSerializer
A subclass of
Serializerthat serializesTypedArray(in particularBuffer) andDataViewobjects as host objects, and only stores the part of their underlying `A… - class v8.Deserializer
- class v8.GCProfiler
This API collects GC data in current thread.
- class v8.Serializer
Interfaces 19
- interface After
Called immediately after a promise continuation executes.
- interface Before
Called before a promise continuation executes.
- interface CPUProfileHandle
- interface CPUProfileOptions
- interface GCProfilerResult
- interface HeapCodeStatistics
- interface HeapInfo
- interface HeapProfileHandle
- interface HeapProfileOptions
- interface HeapSnapshotOptions
- interface HeapSpaceInfo
- interface HeapSpaceStatistics
- interface HeapStatistics
- interface HookCallbacks
Key events in the lifetime of a promise have been categorized into four areas: creation of a promise, before/after a continuation handler is called or around an await,…
- interface Init
Called when a promise is constructed.
- interface PromiseHooks
- interface Settled
Called when the promise receives a resolution or rejection value.
- interface SyncCPUProfileHandle
- interface SyncHeapProfileHandle
Types 2
Variables 1
- const v8.promiseHooks
The
promiseHooksinterface can be used to track promise lifecycle events.
Namespaces 1
- namespace v8.startupSnapshot
The
v8.startupSnapshotinterface can be used to add serialization and deserialization hooks for custom startup snapshots.