node:perf_hooks
Node's [perf_hooks][nodejs-perf-hooks] module surface, importable through both ESM and
CommonJS:
js
import perf from "node:perf_hooks";
// or
const perf = require("node:perf_hooks");[nodejs-perf-hooks]: https://nodejs.org/api/perf_hooks.html
The module shares its per-realm performance timeline with globalThis.performance:
a mark created through one is observable through the other, and perf.performance is
identical (===) to globalThis.performance.
Exports
| Export | Type | Notes |
|---|---|---|
performance | Performance | The same singleton as globalThis.performance. |
now() | () => number | Equivalent to performance.now(). |
mark(name, options?) | (name, opts) => PerformanceMark | Equivalent to performance.mark. |
measure(name, startOrOptions?, endMark?) | (...) => PerformanceMeasure | Equivalent to performance.measure. |
getEntries() | () => PerformanceEntry[] | Equivalent to performance.getEntries. |
getEntriesByName(name, type?) | (...) => PerformanceEntry[] | Equivalent to performance.getEntriesByName. |
getEntriesByType(type) | (type) => PerformanceEntry[] | Equivalent to performance.getEntriesByType. |
clearMarks(name?) | (name?) => void | Equivalent to performance.clearMarks. |
clearMeasures(name?) | (name?) => void | Equivalent to performance.clearMeasures. |
timeOrigin | number | Same value as performance.timeOrigin. |
nodeTiming | PerformanceNodeTiming | See below. [SameObject]. |
PerformanceEntry | constructor | Same identity as globalThis.PerformanceEntry. |
PerformanceMark | constructor | Same identity as globalThis.PerformanceMark. |
PerformanceMeasure | constructor | Same identity as globalThis.PerformanceMeasure. |
PerformanceObserver | constructor | Same identity as globalThis.PerformanceObserver. |
PerformanceObserverEntryList | constructor | Same identity as globalThis.PerformanceObserverEntryList. |
PerformanceNodeTiming | constructor | Node-only entry constructor; not exposed as a global. |
constants | object | Empty placeholder — Node ships an empty object here for users who run Object.keys(perf_hooks).includes('constants'). |
PerformanceNodeTiming
Extends PerformanceEntry (entryType = "node", name = "node"). Captures realm-startup
moments. Returned by perf_hooks.performance.nodeTiming. The same instance is referenced
across reads ([SameObject]); it also appears in performance.getEntriesByType("node").
ts
In Elide:
interface PerformanceNodeTiming extends PerformanceEntry {
readonly nodeStart: number;
readonly v8Start: number;
readonly environment: number;
readonly bootstrapComplete: number;
readonly loopStart: number;
readonly loopExit: number;
readonly idleTime: number;
}| Field | Value | Reason |
|---|---|---|
nodeStart | performance.timeOrigin | The closest analogue to "process start" available; captured at agent init. |
v8Start | 0 | Truffle JS, not V8 — the field exists for compatibility but has no meaningful value here. |
environment | performance.timeOrigin | The JS environment finishes initialising synchronously alongside the agent. |
bootstrapComplete | performance.timeOrigin | Same — bootstrap is synchronous. |
loopStart | 0 | The embedder does not surface a discrete event-loop start moment. |
loopExit | 0 | The loop has not exited yet for the lifetime of the realm. |
idleTime | 0 | The embedder does not measure event-loop idleness. |
nodeTiming — its values are static
once captured, so a delayed first read does not lose information.
Compatibility with Node
require("node:perf_hooks").performance === globalThis.performance— yes, just like Node.- Constructors imported via the module are the same identity as the global ones — values produced one way are
instanceofthe other. - Async observer-callback delivery uses Elide's microtask checkpoint hook, matching the observable behaviour of Node's promise-microtask-bound delivery.
- The legacy
monitorEventLoopDelay/createHistogram/ PerformanceResourceTiming surfaces are not implemented — the WebIDL source describes only the namespace members listed above.