MemLab: An open source framework for finding JavaScript memory leaks
MemLab finds JavaScript memory leaks by driving a headless browser with Puppeteer through a navigate-away/target/return sequence, then diffing heap snapshots as (SB \ SA) ∩ SA' to find objects that should have been freed. It filters candidates with framework knowledge such as detached React Fiber nodes, then generates and clusters retainer traces from GC roots. A lazily constructed graph-view API supports custom leak detectors, Jest memory assertions and heap analysis. At Meta it helped cut Facebook.com OOM crashes by 50%, React 18's aggressive Fiber cleanup on unmount cut average memory by nearly 25%, and interning Relay cache-key strings cut p99 memory by 20%.
Related posts
- Debugging JavaScript Memory Leaks
Bun mediumAdept
Bun implements V8's writeHeapSnapshot API, so heap snapshots can be loaded and diffed in Chrome DevTools, where a steadily growing Delta column reveals leaks. bun:jsc's heapStats also reports per-type object counts, including objects protected from GC. Passing a Blob instead of a Uint8Array to repeated Response objects cut memory from ~1 GB to ~60 MB by avoiding per-Response copies. Common leak sources are closures retaining JSLexicalScope objects, active AbortSignals kept reachable by listeners (shown via JSC's isReachableFromOpaqueRoots), bound functions, and EventEmitter listeners that are never removed.
- Bun 1.4
Bun mediumAdept
Bun 1.4 adds 1,517 newly passing Node.js test-suite tests, fixes over 2,900 issues, and rewrites Bun from Zig to Rust. JavaScriptCore now uses an extended mimalloc instead of libpas, adding a scavenger thread, partial page clearing and better lazy zeroing. Together with GC timer tuning, segmented-array Strong roots and fewer futex calls, this cuts idle CPU 5x, HTTP server peak memory 13–48%, and Linux startup time in half. New APIs include Bun.Image, Bun.WebView, Bun.markdown, Bun.cron and Bun.Terminal, plus Markdown CPU, heap and bundle profiles and a cross-platform memoryPressure event built on kqueue, PSI and Windows resource notifications.
- Bun v1.0.20
Bun mediumAdept
Bun v1.0.20 cuts memory usage in node:fs async operations by avoiding redundant cross-thread string clones. Benchmarks show fs.readlink and fs.stat dropping from 107 MB to about 45–71 MB RSS, and a fs.writeFile leak with large non-ASCII strings falling from 1,696 MB to 91 MB. HTMLRewriter.transform now accepts strings and ArrayBuffers and has a destructor-timing leak fixed, and fs.readFile/writeFile gain hex and base64 encodings. A Linux setTimeout high-CPU regression is fixed, Bun.spawn gains a resourceUsage report, and debug builds use macOS malloc zones to track native allocations.
- Bun v0.6.9
Bun mediumAdept
Bun v0.6.9 focuses on memory reductions: zero-copy string Response bodies in Bun.serve() and Response (60 MB vs Deno's 425 MB and Node's 1414 MB after 1000 responses of a 12 MB string), 50% less memory for cold bun install, and fixed leaks when importing modules. It also fixes non-ASCII filename imports, mockResolvedValue and missing function properties on mocks in bun test, a GC-related crash in the CommonJS require() loader, and a ~192-byte-per-call leak in node:crypto hashing.
- OpenTelemetry for JavaScript Observability at Zalando
Zalando Engineering mediumAdeptZalando built thin OpenTelemetry-based observability SDKs for Node.js and the browser, sharing a common API package so isomorphic apps can be instrumented consistently. The Node.js SDK autoconfigures from Kubernetes environment variables and ships default runtime metrics (CPU, memory, GC, event loop lag) plus opt-in HTTP/Express instrumentation. The browser SDK was trimmed to about 30 KB by cherry-picking packages and lazy-loading the rest. It exports telemetry via sendBeacon through the Skipper edge proxy, gated on GDPR consent, and is exposed to frontend developers through Rendering Engine renderer APIs. Key lessons include avoiding OpenTelemetry context (Zone.js in browsers, and migration friction from OpenTracing) in favour of passing spans manually, and defining custom histogram buckets so Core Web Vitals such as LCP and CLS get meaningful percentiles.