@hyperfrontend/builder/memorymemory
Opt-in memory monitor and the always-on recover() event-loop yield.
createMemoryMonitor(options?) instruments long-running build phases with snapshot history, threshold-based warnings (high heap, critical heap, step-over-step growth), and a summary line covering peak heap, peak RSS, snapshot count, and elapsed wall-clock time. The companion recover() utility yields control to the event loop and triggers a manual GC cycle when the host process is started with --expose-gc; call it between memory-heavy phases to drain pending I/O microtasks and reclaim transient allocations before the next phase begins.
API Reference
ƒ Functions
Creates an opt-in memory monitor backed by
The monitor records snapshot history, emits threshold warnings when
process.memoryUsage(). The monitor records snapshot history, emits threshold warnings when
check() is called, and is intended for instrumenting long-running build phases. All thresholds default to safe values when omitted.Parameters
| Name | Type | Description |
|---|---|---|
§options | MemoryMonitorOptions | Optional threshold overrides. Each field defaults to a value appropriate for builder workloads (warning 512 MB, critical 768 MB, growth 50 MB). (default: {}) |
Returns
MemoryMonitorA frozen
MemoryMonitor with snapshot, check, logDebug, logSummary, and getSnapshots methods.Example
Recording snapshots between phases
const monitor = createMemoryMonitor({ warningMB: 256, criticalMB: 512, growthMB: 32 })
monitor.check('bundle:start')
await runBundlePhase(ctx, config)
monitor.check('bundle:end')
monitor.logSummary()Yields control to the event loop and triggers a manual garbage-collection cycle when
This is the always-on free utility companion to the opt-in memory monitor. Call it between memory-heavy phases to drain pending I/O microtasks and reclaim transient allocations before the next phase begins.
globalThis.gc is available (Node.js started with --expose-gc). This is the always-on free utility companion to the opt-in memory monitor. Call it between memory-heavy phases to drain pending I/O microtasks and reclaim transient allocations before the next phase begins.
Returns
Promise<void>A promise that resolves after one macrotask tick, post-GC if available.
Example
Yielding between heavy build phases
await runBundlePhase(ctx, config)
await recover()
await runPackagePhase(ctx, config)◈ Interfaces
Monitor instance returned by
createMemoryMonitor.Properties
§
check:(label: string) => MemorySnapshot— Capture a snapshot and emit warnings when configured thresholds are crossed.
§
logDebug:(label: string) => MemorySnapshot— Capture a snapshot and emit a debug-level log line summarizing it.
§
snapshot:(label: string) => MemorySnapshot— Capture a snapshot, append it to the history, and return it.
Single memory measurement captured by the monitor.
Sizes are normalized to megabytes (1 MB = 1024 * 1024 bytes) so callers can compare directly against the configured thresholds.
Sizes are normalized to megabytes (1 MB = 1024 * 1024 bytes) so callers can compare directly against the configured thresholds.