Firefox 8 graduated to the Aurora channel this week, and the development period for what will become Firefox 9 began. Lots of MemShrink activity happened this week, and I think all the changes listed below will make it into Firefox 8.
Avoiding Wasted Memory
I have blogged previously about memory wasted by “clownshoes” bugs. Ed Morley found a webpage that resulted in 700MB of memory being wasted by the PLArena clownshoes bug. Basically, on platforms where jemalloc is used (Windows, Linux), half the memory allocated by nsPresArena (which is built on top of PLArena) was wasted. (On Mac the waste was 11%, because the Mac allocator rounds up less aggressively than jemalloc).
Fixing this problem properly for all PLArenas takes time because it requires changes to NSPR, so I made a spot-fix for the nsPresArena case. This is a particularly big win on very large pages, but it saves around 3MB even on Gmail. This spot-fix has been granted beta approval and so will, barring disaster, make it into Firefox 7.
A Firefox Nightly user did some measurements with different browsers on the problematic page:
- Firefox 8.0a1 before patch: 2.0 GB
- Firefox 8.0a1 after patch: 1.3 GB
- Latest Chrome canary build and dev (15.0.849.0): 1.1GB
- Webkit2Process of Safari 5.1: 1.05 GB
- Internet Explorer 9.0.2: 838 MB
- Latest Opera Next 12.00: 727 MB
So this fix gets Firefox within spitting distance of other browsers, which is good!
In other developments related to avoiding wasted memory:
- Luke Wagner discovered that, on typical websites, most JSScripts are byte-compiled but never run. A JSScript roughly corresponds to a JavaScript function. In hindsight, it’s not such a surprising result — Firefox byte-compiles all loaded JavaScript code, and you can imagine lots of websites use libraries like jQuery but only use a small fraction of the functions in the library. Making byte-compilation lazy could potentially save MBs of memory per compartment. But that will require some non-trivial reworking of the JS engine, and so is unlikely to happen in the short-term.
- Kyle Huey avoided a small amount (~100KB per browser process) of waste due to rounding up in XPT arenas.
Improving about:memory
I made some progress on a Valgrind tool to help identify the memory that is currently reported only by the “heap-unclassified” bucket in about:memory. It’s called “DMD”, short for “Dark Matter Detector”. It’s in early stages and I still need to teach it about most of Firefox’s memory reporters, but it’s already spitting out useful data, which led to me and Ehsan Akhgari landing memory reporters for the JS atom table and the Hunspell spell checker. We also now have some insight (here and here) about memory usage for very large pages.
Mounir Lamouri turned on the memory reporter for the DOM that he’s been working on for some time. This shows up under “dom” in about:memory. There are still some cases that require handling; you can follow the progress of these here.
Andrew McCreight replaced about:memory’s buttons so you can force a cycle collection without also forcing a garbage collection, which may be useful in hunting down certain problems.
Finally, Sander van Veen added the existing “js-compartments-user” and “js-compartments-system” to the statistics collected by telemetry (his first landed patch!), and I did likewise for the “storage/sqlite” reporter. I also added a new “tjit-data/trace-monitor” memory reporter that accounts for some of the memory used by TraceMonkey.
Miscellaneous
Igor Bukanov tweaked the handling of empty chunks by the JavaScript garbage collector. That sounds boring until you see the results on Gregor Wagner’s 150-tab stress test: resident memory usage dropped 9.5% with all 150 tabs open, and dropped by 27% after all those tabs were closed.
Brian Hackett fixed a memory leak in type inference, which gets it one step closer to being ready to land.
Christian Höltje fixed a leak in his “It’s All Text” add-on that was causing zombie compartments. This fix will be in version 1.6.0, which is currently awaiting to receive AMO approval, but can be obtained here in the meantime. This fix and last week’s fix of a memory leak in LastPass are very encouraging — per-compartment reporters in about:memory have, for the first time, given add-on developers a reasonable tool for identifying memory leaks. I hope we can continue to improve the situation here. Several people have asked me for documentation on how to avoid memory leaks in add-ons. I’m not the person to write that guide (I’m not a Gecko expert and I know almost nothing about add-ons) but hopefully someone else can step up to the plate.
Bug counts
Here’s the change in MemShrink bug counts.
- P1: 30 (-0, +1)
- P2: 64 (-4, +6)
- P3: 36 (-5, +0)
- Unprioritized: 1 (-2, +1)
Good progress on P3 bugs, but they’re the least important ones. Other than that, new bugs are still being reported faster than they’re being fixed. If you want to help but don’t know where to start, feel free to email me or ping me on IRC and I’ll do my best to help get you involved.






