{"id":9,"date":"2011-08-26T16:14:10","date_gmt":"2011-08-26T16:14:10","guid":{"rendered":"http:\/\/blog.mozilla.org\/nfroyd\/?p=9"},"modified":"2011-08-26T16:14:10","modified_gmt":"2011-08-26T16:14:10","slug":"making-firefox-work-with-syzygy","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nfroyd\/2011\/08\/26\/making-firefox-work-with-syzygy\/","title":{"rendered":"making firefox work with syzygy"},"content":{"rendered":"<p>The good folks at Google have written a clever tool called Syzygy, which is part of the <a href=\"http:\/\/code.google.com\/p\/sawbuck\/\">Sawbuck project<\/a>.\u00a0 The best summary of Syzygy comes from <a href=\"http:\/\/code.google.com\/p\/sawbuck\/wiki\/SyzygyDesign\">its design document<\/a>:<\/p>\n<blockquote><p>Syzygy is a suite of tools to perform profile-guided, function-level reordering of 32-bit Windows PE executables, to optimize their layout improved performance, notably for improved paging patterns.<\/p><\/blockquote>\n<p>Google wrote Syzygy for use with Chrome, but the tool is equally applicable to any large application where you want to improve performance&#8230;like Firefox.\u00a0 In this case, we&#8217;re concerned with improving the layout of libxul, as that&#8217;s where the bulk of the Firefox code lives.\u00a0 Working with Syzygy involves four major steps:<\/p>\n<ol>\n<li>Instrumenting the application binary in question;<\/li>\n<li>Running the application to collect profile data (function addresses along with invocation time);<\/li>\n<li>Passing the profile data through an ordering generator, which comes up with the order in which functions should be laid out in the optimized binary; and finally<\/li>\n<li>Relinking the application binary using the ordering from step 3.<\/li>\n<\/ol>\n<p>Step 1 is pretty easy; Firefox just needs to be compiled with <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ays5x7b0%28VS.80%29.aspx\">Visual Studio&#8217;s \/PROFILE switch<\/a> to ensure that the instrumenter has all the information it needs.\u00a0 Steps 3 and 4 are likewise straightforward.<\/p>\n<p>Step 2 appears to be the tricky part.\u00a0 Being good&#8211;lazy&#8211;computer programmers, the Google folks wrote a number of scripts and programs to automate this process, as well as some benchmarking infrastructure.\u00a0 However, the scripts are written with Chrome in mind; many places have Chrome-specific bits hardcoded.\u00a0 This is, of course, totally understandable, but it makes using those scripts with other programs difficult.<\/p>\n<p>Over the past couple of weeks, I&#8217;ve been working at making Syzygy cooperate with Firefox.\u00a0 If you&#8217;re interested, you can see the modifications I&#8217;ve made in my <a href=\"https:\/\/github.com\/froydnj\/sawbuck-firefox\/tree\/firefox-mods\">sawbuck github project<\/a>.\u00a0 Things are working well enough that I can now run:<\/p>\n<blockquote>\n<pre>Debug\/py\/Scripts\/benchmark --user-data-dir flobbity --no-preload --no-prefetch ~\/ff-build\/dist\/bin\/firefox.exe<\/pre>\n<\/blockquote>\n<p>(The <tt>--no-{preload,prefetch}<\/tt> options are required to work around Chrome-specific code that didn&#8217;t seem worth ripping out; the <tt>--user-data-dir<\/tt> specifies what profile to use when launching Firefox.)\u00a0 After waiting for a minute or two, the benchmark script reports:<\/p>\n<blockquote>\n<pre>RESULT firefox.exe: SoftPageFaults= [23495, 32139, 23356, 23343, 23299, 23167, 23063, 23141, 23113, 23267]\r\nRESULT firefox.exe: HardPageFaults= [1158, 10, 3, 3, 4, 2, 2, 2, 3, 2]<\/pre>\n<\/blockquote>\n<p>This is for an unoptimized binary, of course.\u00a0 You can clearly see the OS&#8217;s page cache at work in runs after the first.<\/p>\n<p>The scripts are not quite perfect yet.\u00a0 In particular, the call traces necessary to perform reordering don&#8217;t seem to be generated, for some peculiar reason that I haven&#8217;t ferreted out.\u00a0 Also, the script will indiscriminately kill any Mozilla-related apps running along with the Firefox instances being benchmarked; I couldn&#8217;t find any good way to limit the killing to windows associated with a particular profile.\u00a0 (IIUC the Chrome code correctly, it sets the window text of a hidden window to the full path to the profile directory in use.)\u00a0 But a good bit seems to work; hopefully progress will come faster now that the groundwork has been laid.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The good folks at Google have written a clever tool called Syzygy, which is part of the Sawbuck project.\u00a0 The best summary of Syzygy comes from its design document: Syzygy is a suite of tools to perform profile-guided, function-level reordering of 32-bit Windows PE executables, to optimize their layout improved performance, notably for improved paging [&hellip;]<\/p>\n","protected":false},"author":320,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts\/9"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/users\/320"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}