{"id":914,"date":"2011-06-21T15:36:35","date_gmt":"2011-06-21T04:36:35","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=914"},"modified":"2011-06-21T18:06:19","modified_gmt":"2011-06-21T07:06:19","slug":"you-make-what-you-measure","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2011\/06\/21\/you-make-what-you-measure\/","title":{"rendered":"You make what you measure"},"content":{"rendered":"<p>Inspired by <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=625305\">Shaver&#8217;s patch<\/a>, I implemented some <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=661474\">per-compartment stats<\/a> in about:memory.\u00a0 I then visited <a href=\"http:\/\/techcrunch.com\/\">TechCrunch<\/a> because I know it stresses the JS engine.\u00a0 Wow, there are over 70  compartments!\u00a0 There are 20 stories on the front page.\u00a0 Every story has a  Facebook &#8220;like&#8221; button, a Facebook &#8220;send&#8221; button, and a Google &#8220;+1&#8221;  button, and every button gets its own compartment.<\/p>\n<p>That sounds like a  bug, but it&#8217;s <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=664067\">probably not<\/a>.\u00a0 Nonetheless, every one of those buttons had an entry in about:memory that looked like this:<\/p>\n<p><a href=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c11.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-916 alignleft\" title=\"c1\" src=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c11.png\" alt=\"Old compartment measurements\" width=\"857\" height=\"184\" srcset=\"https:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c11.png 857w, https:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c11-300x64.png 300w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/a><\/p>\n<p>(The &#8216;object-slots&#8217; and &#8216;scripts&#8217; and &#8216;string-chars&#8217; measurements are also new, courtesy of <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=571249\">bug 571249<\/a>.)<\/p>\n<p>Ugh, 255,099 bytes for a compartment that has only 971 bytes (i.e. not much) of scripts?\u00a0 Even worse, this is actually an underestimate because there is another 68KB of tjit-data memory that isn&#8217;t being measured for each compartment.\u00a0 That gives a total of about 323KB per compartment.\u00a0 And it turns out that no JIT compilation is happening for these compartments, so all that tjit-data and mjit-code space is allocated but unused.<\/p>\n<p>Fortunately, it&#8217;s not hard to avoid this wasted space, by lazily initializing each compartment&#8217;s <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=661068\">TraceMonitor<\/a> and <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=665404\">JaegerCompartment<\/a>.\u00a0 With that done, the entry in about:memory looks like this:<\/p>\n<p><a href=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c22.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft\" title=\"c2\" src=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/06\/c22.png\" alt=\"New compartment measurements\" width=\"863\" height=\"180\" \/><\/a><\/p>\n<p>That&#8217;s an easy memory saving of over 20MB for a single webpage.\u00a0 The per-compartment memory reporters haven&#8217;t landed yet, and may not even land in their current form, but they&#8217;ve already demonstrated their worth.\u00a0 You make what you measure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inspired by Shaver&#8217;s patch, I implemented some per-compartment stats in about:memory.\u00a0 I then visited TechCrunch because I know it stresses the JS engine.\u00a0 Wow, there are over 70 compartments!\u00a0 There are 20 stories on the front page.\u00a0 Every story has a Facebook &#8220;like&#8221; button, a Facebook &#8220;send&#8221; button, and a Google &#8220;+1&#8221; button, and every [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4550,4543,4544,467],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/914"}],"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=914"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/914\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}