new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

runtime/memory

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

v8.writeHeapSnapshot() creates heap snapshot file

The v8.writeHeapSnapshot() function creates a heap snapshot file with an auto-generated name and returns the path to the snapshot file as a string. It can be imported from the "node:v8" module.

Heap snapshots are .heapsnapshot files

Bun implements V8's heap snapshot API to capture the heap at runtime. The resulting files have a .heapsnapshot extension and can be used to debug memory leaks in JavaScript/TypeScript applications.

Example: capture heap snapshot with v8.writeHeapSnapshot()

import v8 from "node:v8"; // Creates a heap snapshot file with an auto-generated name const snapshotPath = v8.writeHeapSnapshot(); console.log(`Heap snapshot written to: ${snapshotPath}`);

Bun has two separate heaps

Bun has two heaps: one for the JavaScript runtime, and one for everything else.

heapStats() from bun:jsc module measures JavaScript heap

The bun:jsc module exposes heapStats() function to measure JavaScript heap memory usage. Import: import { heapStats } from "bun:jsc"; and call heapStats() to get detailed heap statistics including heapSize, heapCapacity, extraMemorySize, objectCount, and a breakdown of objectTypeCounts.

Bun.gc() forces garbage collection

Call Bun.gc(true) for synchronous garbage collection or Bun.gc(false) for asynchronous garbage collection.

Bun.generateHeapSnapshot() creates heap snapshot

Use Bun.generateHeapSnapshot() to take a heap snapshot that shows which objects are not being freed. The result can be written to a file and viewed with Safari or WebKit GTK developer tools.

How to view heap snapshot in Safari Developer Tools

To view a heap snapshot in Safari: (1) Open Developer Tools, (2) Click "Timeline", (3) Click "JavaScript Allocations" in the left menu (may require clicking the pencil icon to show all timelines), (4) Click "Import" and select the heap snapshot JSON file.

Bun.unsafe.mimallocDump() for native heap stats

Call Bun.unsafe.mimallocDump() to print a summary of non-JavaScript memory usage from the mimalloc heap that Bun uses for non-JavaScript memory.

Give your agent this brain