Incremental GC now in Firefox Aurora
We’ve been holding our breath for a while on incremental GC (IGC), but now we can exhale: it’s currently in Aurora (Firefox 16) and working well. IGC comes from months of hard work by Bill McCloskey, who designed and implemented the incrementalization, and also spent a long time tuning performance and fixing the many subtle bugs that inevitably come up when you try to change the memory management of a complex system. Huge kudos to Bill for carrying through such a tough and important project.
Simply, incremental GC means fewer noticeable pauses. If you run Firefox with not too many tabs (like I do), then your GC pauses are probably around 100-200ms, which is a very noticeable glitch. If run with hundreds of tabs, then you might see pauses more like 500ms, which feels like a freeze. Incremental GC breaks up that time into 10-20ms slices, which are generally not noticeable, and spreads them out over time.
So this is a huge improvement, but keep in mind there is no perfect fix for GC pauses. For any incremental GC system, if memory is being allocated too fast, incremental GCs will not be able to keep up, and the system will be forced to pause for a full GC in order to avoid running out of memory . But for the most part, IGC seems to be doing the trick, so if you’re still getting bad GC pauses, please let us know so we can fix them.
Another thing to note is that technically what’s just reached Aurora is incremental marking. Our GC has two phases, mark and sweep, and the sweep phase is not incremental yet. The last slice of GC, which includes sweeping, seems to often take 50 ms or so, which is nearly negligible for many purposes but would still disturb smooth animation.
Fortunately, Bill and Jon Coppeard (who recently joined the JS team working out of London) are making rapid progress on incremental sweeping as well. Bill is also continuing to tune IGC to keep pauses short on various machines and under various conditions.
[Update 3:11pm 20 Jul 2012: Bill reports in bug 775365 that the current work is for incrementalizing sweeping of some kinds objects. Apparently sweeping each kind of thing incrementally presents its own issues so getting incremental all the way through will take longer.]
 Generational GC (also under construction) will solve this problem for programs that rapidly allocate many short-lived objects. If you’re rapidly allocating long-lived objects, you’re being very mean to your GC and it will be very mean back to you.