Skip to content

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

Mozilla Hacks 4 min read Case study mediumAdept

Improving Firefox stability with this one weird trick

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.

Assumes: virtual memory basicsswap files

Related posts

  • Tab Unloading in Firefox 93

    Mozilla Hacks mediumAdept

    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.

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

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

  • Improved Process Isolation in Firefox 100

    Mozilla Hacks hardMaster

    Firefox 100 enables Win32k Lockdown on Windows, using PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY to block web content processes from calling the historically exploitable win32k.sys kernel APIs. Getting there meant moving every graphics and widget operation out of the content process. Painting moved to WebRender in the GPU process, Canvas 2D is recorded and replayed over IPC, and WebGL gained a validating child/parent API. Form controls are now drawn by Firefox itself instead of as native widgets, complex-script line breaking is forwarded over IPC with caching, and a fix stops injected third-party DLLs from breaking COM. Skipping those DLLs also made opening new tabs about 15% faster, and equivalent lockdowns of WindowServer on macOS and X11 on Linux sped process startup by 30-70% on Mac.

  • Fixing the Git Blame Beachball

    Zed mediumAdept

    Committing with many files open froze Zed for about 10 seconds. Instruments' Thread State and Narrative views showed the main thread stuck in a condition-variable wait and repeatedly woken by git. The cause was Inline Git Blame: it listened for git index changes in every open buffer, so one commit spawned 257 concurrent git processes. A priority inversion made it worse, because the 5ms block_with_timeout depended on a GPUI timer task scheduled below background tasks, so the main thread waited seconds instead of milliseconds. Both bugs were fixed in v0.133.7.

The quest for software engineering knowledge.

Look:
Layout: