{"id":1908,"date":"2012-05-07T15:59:36","date_gmt":"2012-05-07T04:59:36","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=1908"},"modified":"2012-06-08T14:13:32","modified_gmt":"2012-06-08T03:13:32","slug":"update-on-leaky-add-ons","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2012\/05\/07\/update-on-leaky-add-ons\/","title":{"rendered":"Update on Leaky Add-ons"},"content":{"rendered":"<p>Leaky add-ons are a big problem, but there&#8217;s been lots of action relating to them recently.\u00a0 What follows is a summary of the situation and a request for help from currently Nightly testers who use add-ons.<\/p>\n<h3>Two Steps Forward<\/h3>\n<p>Kyle Huey&#8217;s <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=695480\">patch<\/a> to <a href=\"http:\/\/blog.kylehuey.com\/post\/21892343371\/fixing-the-memory-leak\">prevent Chrome-to-Content leaks<\/a> landed recently.\u00a0 In theory it would prevent almost all add-ons zombie compartments, which constitute the majority of leaks from add-ons.\u00a0 And in practice, it appears to be working splendidly.<\/p>\n<p>I <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=695480#c48\">did<\/a> <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=695480#c50\">some<\/a> <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=695480#c51\">testing<\/a> of eight add-ons that are known to leak: <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=727938\">McAfee SiteAdvisor 3.4.1<\/a>(the old version that leaked every content compartment), <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=669730\">Firebug 1.9.1<\/a>, <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=735401\">PicPasso 1.0.1<\/a>, <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=740085\">LoL 1.5<\/a>, <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=742232\">YouTube Ratings Preview 1.03<\/a>, <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=745149\">Enter Selects 7<\/a>, <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=747167\">HttpFox 0.8.10<\/a>, and <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=728589\">Link Resolve 0.7<\/a>.\u00a0 I tested with a &#8220;before&#8221; browser build that lacked Kyle&#8217;s patch, and an &#8220;after&#8221; browser build that had it.\u00a0 For every one of the tested add-ons, I could reproduce the zombie compartment(s) with the &#8220;before&#8221; build, but could <em>not<\/em> reproduce any zombie compartment(s) with the &#8220;after&#8221; build.\u00a0 In other words, the patch worked perfectly.<\/p>\n<p>To understand how important this is, consider <a href=\"http:\/\/blog.kylehuey.com\/post\/21892343371\/fixing-the-memory-leak#comment-519424145\">this comment<\/a> on Kyle&#8217;s blog describing the effect of the patch.<\/p>\n<blockquote><p>I seem to be seeing really significant improvements from this. Normally Fx would start at 170MB and by the end of the day that would often be creeping up to 800 or 900 MB. Today using latest nightly I again started at 170, but now at the end of the day I&#8217;m only at 230MB!<\/p><\/blockquote>\n<p>That&#8217;s a <strong>4x reduction<\/strong> in memory consumption.<\/p>\n<p>What effect does this have?\u00a0 The obvious <a href=\"http:\/\/blog.mozilla.org\/nnethercote\/2012\/02\/08\/the-benefits-of-reducing-memory-consumption-2\/\">benefit of reduced memory consumption<\/a> is that there will be less potential for paging.\u00a0 For example, if the above user is on a low-end machine without much RAM, a reduction in memory consumption from 800+MB to 230MB might greatly reduce paging, which would make Firefox much faster.<\/p>\n<p>However, what if the user has a high-end machine with 16GB of RAM?\u00a0 Then paging isn&#8217;t an issue.\u00a0 But this improvement will still be a big deal on such a machine.\u00a0 This is because garbage collection and cycle collection cause pauses, and the length of the pauses are roughly proportional to the amount of live heap memory.\u00a0 (Incremental garbage collection will soon be enabled, which will result in smaller garbage collection pauses, but there are no plans for incremental cycle collection and so cycle collection pauses will still be relevant.)\u00a0 So even on high-end machines with lots of RAM, leaks can greatly hurt browser performance.\u00a0 In other words, add-on leaks are a <a href=\"https:\/\/wiki.mozilla.org\/Performance\/Snappy\">Snappy<\/a> issue just as much as they are a <a href=\"https:\/\/wiki.mozilla.org\/Performance\/MemShrink\">MemShrink<\/a> issue.<\/p>\n<h3>One Step Back<\/h3>\n<p><strong>[Update: Kyle <a href=\"http:\/\/blog.mozilla.org\/nnethercote\/2012\/05\/15\/additional-update-on-leaky-add-ons\/\">found a simple way to fix this problem<\/a> with the Add-on SDK.]<\/strong><\/p>\n<p>So Kyle&#8217;s patch is great, but the cutting of the chrome-to-content references was unlikely to be totally free of side-effects.\u00a0 And sure enough, last week Josh Matthews noticed that Dietrich Ayala&#8217;s <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=751420\">Wallflower add-on was causing many zombie compartments<\/a>.\u00a0 Hmm, wasn&#8217;t Kyle&#8217;s patch supposed to stop exactly that?\u00a0 Well, it was expected to stop the most common cases, but there are some other leaks that could still cause zombie compartments.<\/p>\n<p>The weird thing with this leak is that Wallflower is a really simple add-on.\u00a0 It&#8217;s built with the Add-on SDK and is only a <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=751466#c9\">few lines of code<\/a>.\u00a0 It turns out that Kyle&#8217;s patch <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=749526\">caused the Add-on SDK to leak badly<\/a>.\u00a0 The exact reason is complex;\u00a0 you can see Kyle&#8217;s explanation <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=751420#c12\">here<\/a>.<\/p>\n<p>This sounds really bad.\u00a0 Lots of add-ons are built with the Add-on SDK.\u00a0 Have we just exchanged one class of add-on leaks for another?\u00a0 I don&#8217;t believe so, for two reasons.<\/p>\n<ol>\n<li>Kyle&#8217;s patch prevents the single most common class of add-on leaks, and the Add-on SDK leak it caused is a much more obscure and unlikely leak.\u00a0 It&#8217;s unfortunate that this obscure leak happened to be in a piece of code that&#8217;s used by lots of add-ons.<\/li>\n<li>This obscure leak only occurs in old versions of the Add-on SDK.\u00a0 The leak doesn&#8217;t occur with the latest version, which is 1.6.1.\u00a0 Indeed, when Dietrich rebuilt Wallflower with version 1.6.1 the problem went away.<\/li>\n<\/ol>\n<p>Still, the situation is far from ideal, because lots of add-ons are still built with older SDK versions.\u00a0 So, what to do?\u00a0 There&#8217;s a bug open <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=751466\">discussing this question<\/a>, but it&#8217;s gotten bogged down due to differing opinions on what to do.\u00a0 Version 1.6.1 happened to fix all leaks in the Add-on SDK that were known prior to this problem, so we should be encouraging add-on authors to rebuild with it anyway.<\/p>\n<p>In the meantime,<strong> if you use Nightly builds and use add-ons, please <a href=\"https:\/\/developer.mozilla.org\/en\/Zombie_Compartments#Reactive_checking\">monitor about:compartments<\/a> and file bugs if you find that any add-ons are causing zombie compartments<\/strong>.\u00a0 If Wallflower is representative, the leaks will be very bad and so shouldn&#8217;t be hard to spot.\u00a0 Firefox 15 is scheduled for release on August 28th;\u00a0 we need as many affected add-ons to be rebuilt with the latest SDK before that date to minimize potential problems.<\/p>\n<h3>Problems with FUEL<\/h3>\n<p>Another cause of high memory consumption in add-ons is FUEL.\u00a0 I know very little about it other than it&#8217;s <span style=\"text-decoration: line-through;\">also part of the Add-on SDK<\/span> sort of a proto-version of the Add-on SDK.\u00a0 The details are <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=750454\">here<\/a> and <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=750953\">here<\/a>.\u00a0 This is causing bad performance in <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=730546\">Readability<\/a> and probably other add-ons.\u00a0 Something to be aware of.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Leaky add-ons are a big problem, but there&#8217;s been lots of action relating to them recently.\u00a0 What follows is a summary of the situation and a request for help from currently Nightly testers who use add-ons. Two Steps Forward Kyle Huey&#8217;s patch to prevent Chrome-to-Content leaks landed recently.\u00a0 In theory it would prevent almost all [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119,30,4544,4546],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/1908"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/comments?post=1908"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/1908\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=1908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=1908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=1908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}