Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Mozilla Hacks 6 min read Deep dive mediumAdept

Tab Unloading in Firefox 93

Firefox 93 on Windows unloads memory-heavy background tabs in least-recently-used order when system memory is critically low, keeping them in the tab bar and restoring scroll position and form data on reselect. Detection pairs a Windows low-physical-memory notification (CreateMemoryResourceNotification) with periodic checks of available commit space against a configurable threshold, because Windows does not overcommit and allocations fail once commit space runs out, even with free physical RAM. A month-long Nightly experiment showed fewer overall crashes and longer sessions, but higher average memory use (explained by survivorship bias) and a larger share of OOM crashes, possibly because unloading a tab needs a JavaScript GC pass that itself requires memory. Pinned tabs and tabs playing audio, using picture-in-picture or WebRTC are deprioritized, and a new about:unloads page exposes the ordering.

Assumes: virtual memory and swapWindows commit charge

Related posts

  • Improving Firefox stability with this one weird trick

    Mozilla Hacks mediumAdept

    Out-of-memory crashes on Windows are often caused by exhaustion of commit space rather than physical RAM, since Windows forbids overcommit and graphics drivers commit memory for texture backing that is rarely used. Firefox 105 stops crashing immediately on a failed allocation and instead stalls briefly and retries, giving Windows time to grow the swap file or letting a memory-hungry content or GPU process die and free memory. The change cut out-of-memory browser crashes per usage hour by more than 70%, at the cost of brief jank and a small rise in tab crashes that Mozilla is now working to reduce.

  • 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.

  • MemLab: An open source framework for finding JavaScript memory leaks

    Meta Engineering mediumAdept

    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%.

  • Improving Firefox responsiveness on macOS

    Mozilla Hacks hardMaster

    Firefox 103 on macOS became much more responsive under load after its customized jemalloc allocator stopped using the deprecated OSSpinLock, which spins and yields in user space and can nearly live-lock on busy systems. The public os_unfair_lock replacement sleeps immediately on contention and regressed some benchmarks by up to 30%. The fix uses the undocumented os_unfair_lock_with_options() with OS_UNFAIR_LOCK_ADAPTIVE_SPIN and OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION to get kernel-space adaptive spinning, which matches OSSpinLock on idle machines, is far better under load and uses less power. Pre-10.15 systems fall back to os_unfair_lock with manual x86-64 pause-instruction spinning, and fork() safety requires pthread_atfork handlers because the lock stores mach thread IDs.

  • Bun v1.2.2

    Bun mediumAdept

    Bun v1.2.2 fixes 38 bugs and cuts idle JavaScript memory usage by 10–30% (28% for Next.js, 11% for Elysia). The fix integrates JavaScriptCore's garbage collector timers into Bun's event loop, and on Linux GC thread suspension moves from SIGUSR1 to SIGPWR so it no longer conflicts with applications that use SIGUSR1. The release also fixes a vite build regression caused by an event-loop bug in async file writes, and improves reliability of Bun.SQL prepared statements, S3 multipart uploads and the CSS parser. Node.js compatibility additions include fs.glob, NODE_PATH resolution, and fixes for fs.Dir, createRequire on virtual paths, pnpm, and DuckDB native modules.

The quest for software engineering knowledge.

Look:
Layout: