9 ms·
A big step towards Firefox generational and compacting GC
- doctorpangloss 13y agoFrom Terrence Cole: >Exact rooting is required for us to use GC algorithms that relocate objects in memory. It will allow us to implement compacting GC to save memory and generational GC to push our performance to the next level. For a comprehensive overview of a good open source GC, check out Mono's description of theirs: http://www.mono-project.com/Generational_GC http://www.mono-project.com/Generational_GC Browser GC is really tricky. The browser provides all sorts of complicated native services, like a flexible rendering engine (you know, HTML), recording audio, LocalStorage—really complex stuff implemented efficiently in C++ and with cross-platform support. All of these native objects can be accessed/instantiated from Javascript. Hence the GC is especially well tuned, on top of the security requirements around dealing with untrusted code running trusted code in general. It's a big undertaking for sure.
- nickik 13y agoWow, that must have been a lot of freaking work. Testing this must be nightmare, if you have on native pointer left the browser could essentially randomly crash. Pretty cool stuff. I really want to see the performance changes the GC can get.
- venomsnake 13y agoIsn't that problem right in the domain of automated testing and static code analysis?
- evilpie 13y agoWe do both, but it's still very tideous. After a while the dynamic analysis only caught false postives (something on the stack looked like a pointer). The static analysis had to be updated when new potential hazardous cases became obvious. https://wiki.mozilla.org/Javascript:SpiderMonkey:ExactStackRooting https://wiki.mozilla.org/Javascript:SpiderMonkey:ExactStackR...
- AndrewDucker 13y agoYou've got a typo in your URL there - missing 'n' in 'rooting'
- mccr8 13y agoWork on generational GC has been proceeding in parallel with the exact rooting work. You can see what the current generational GC performance is on standard benchmarks like Octane by looking at the "Firefox (Ion, GGC)" line on http://arewefastyet.com/ http://arewefastyet.com/
- saurabhnanda 13y agoPlease excuse my naivety, but I have only recently gotten interested in compilers, memory management, etc. [1] Can someone please explain to me why GC isn't implemented as a library that can be used by any runtime/VM? We recently had a generational GC land in Ruby 2.1 Few languages out there specially target JVM because of its GC story. Wouldn't everyone benefit from a common code-base with rock-solid GC algorithms & implementations? Analogous to crypto libraries. [1] After getting sick of the fact that all the "new age" languages use shit-loads of resources for, essentially, achieving trivialities. We were able to do the same things using 386 PCs with a few megs or RAM for which, today, we need 2 GHz multi-core CPUs and 8 GB of RAM. PS: Not trying to downplay the work done in bringing better memory management to Firefox. I would really appreciate Firefox not using up 1.3GB of memory -- that was one of the reasons I had to fork out INR 5,000 for an extra 8GB of RAM recently.
- vidarh 13y agoThe hard part is not the high level algorithm - most of the common ones can be prototyped for toy systems in trivial numbers of lines. The hard part is system interactions. E.g. the GC needs a way to identify all the "roots" (references from outside the heap, such as registers, the stack, or pointers that may have been retained by external libraries etc.). It also needs a way to identify which parts of an object are pointers and this varies with language. "Generic" GC's like Boehm's solve this by assuming you've done nothing to obscure the pointer, and then assumes everything that could be a pointer into the heap is, but this fails miserably for any language implementation that uses bits for type tagging, for example, and retains too much memory in many other situations because it isn't precisely determining which fields are pointers. Then you have issues like threading models (threading and GC are intimately linked, as if you don't block all threads during marking or moving/collection, you have all kinds of additional exciting issues to deal with to ensure you don't break things)
- blt 13y agopointers that may have been retained by external libraries Oh, if only this were easy...
- 13y ago
- ksec 13y agoStill waiting for e10sM2. I hope after this is finish and done they can move on to it. Firefox really needs some help in its snappiness area.
- Ygg2 13y agoTo be honest I haven't noticed it being sluggish, except when loading a 10 tabs when waking from hibernate. These days Chrome chokes with same amount of tabs that FF deals with easily. Chrome does sometimes win with the JS demos (mainly that 3D period table demo).
- agumonkey 13y agoChrome wins on psychology, it's uber fast on start and with few tabs, then it gets a bit slower than firefox, which is relatively constant in its non-snappiness (it's not slow but you notice tiny lags in the UI regularly)
- Ygg2 13y agoTo be honest I haven't noticed that it's non-snappy (I am on Nightly but use Regular at home). I'm bit biased towards Mozilla, but I don't think it is lacks much polish. Chrome dev tools are better, but the gap is closing in that area.
- agumonkey 13y agoWell, my laptop is from 2007, so I may "suffer" more from the sum of tiny tiny delays that I don't perceive in Chrome. I also use Nightly but I was under the impression that often Stable releases were a tiny bit faster (maybe some debug features disabled...) except for major feature upgrades like gc, jit etc ps: about devtools and overall catch up, Mozilla is really impressive, they've been pushing hard and regularly on difficult topics (memory, javascript, standards, devtools). So much they suffer from under-publicity, I often realize their devtools could do X many weeks after it's been released.
- ksec 13y ago
- afsina 13y agoIs this the equivalent work of Oilpan project for Chromium-Blink? https://groups.google.com/a/chromium.org/d/msg/blink-dev/59fb1FIirx0/u1EV00Ca5sgJ https://groups.google.com/a/chromium.org/d/msg/blink-dev/59f... Doc: https://docs.google.com/document/d/1y7_0ni0E_kxvrah-QtnreMlzCDKN3QP4BN1Aw7eSLfY/edit https://docs.google.com/document/d/1y7_0ni0E_kxvrah-QtnreMlz...
- pcwalton 13y agoNo, Oilpan is different; it's a garbage collector for C++ objects, while exact rooting is for JS objects. Oilpan has more in common with the XPCOM cycle collector in purpose (although the approach is different), which Firefox has had for several years now but which WebKit has had no equivalent to.
- DannyBee 13y agoRight, and on the flip side, V8 has had a generational, incremental JS collector for quite a while :)
- mccr8 13y agoFor what its worth, it looks like v8 has had incremental GC since 2011 ( http://blog.chromium.org/2011/11/game-changer-for-interactive.html http://blog.chromium.org/2011/11/game-changer-for-interactiv... and generational GC for longer) while Firefox has had IGC since 2012 ( https://blog.mozilla.org/javascript/2012/08/28/incremental-gc-in-firefox-16/ https://blog.mozilla.org/javascript/2012/08/28/incremental-g... ).
- sliverstorm 13y agoCan anyone comment on what this will mean for Firefox in rough terms? Less bloat in long-running processes? Less memory usage in general?
- kevingadd 13y agoThe eventual introduction of compacting and generational collection will: Dramatically reduce the cost of GC for short-lived objects (dramatically, to the point of producing something like 5-10x wins on some of the stupidly tuned microbenchmarks typically used to compare JS runtimes) Reduce typical heap fragmentation (essential for long-running processes - imagine a facebook/gmail tab left open for days) Potentially improve computational performance (compacting your GC heap will improve memory locality in some scenarios, which means the CPU cache can be used more efficiently, which will make JS code manipulating small objects much faster) Reduce average GC pause duration and reduce the frequency of GC pauses In summary, generational collection is a big win for the things users tend to care about, if you look at what the advantages mean for applications. Compacting is less important, but tends to be nice too.