{"id":200,"date":"2013-08-02T12:15:28","date_gmt":"2013-08-02T16:15:28","guid":{"rendered":"http:\/\/blog.mozilla.org\/nfroyd\/?p=200"},"modified":"2013-08-02T12:15:28","modified_gmt":"2013-08-02T16:15:28","slug":"i-got-99-problems-and-compilation-time-is-one-of-them","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nfroyd\/2013\/08\/02\/i-got-99-problems-and-compilation-time-is-one-of-them\/","title":{"rendered":"I got 99 problems&#8230;and compilation time is one of them"},"content":{"rendered":"<p>Over the past week or so, there have been a few conversations on <tt>#developers<\/tt> about the ever-increasing time it takes to compile Firefox.\u00a0 Compiling Firefox <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=783357#c0\">used to be a relatively quick affair<\/a> (well, on my machine, at least) and I&#8217;ve grown dissatisfied recently with builds taking ever-longer.\u00a0 All of the aforementioned discussions have boiled down to &#8220;well, we&#8217;re adding a lot of code and all that code takes longer to compile.&#8221;<\/p>\n<p>Surely that can&#8217;t be the whole story.\u00a0 A mozilla-central build from a day or two took about 24 minutes on my machine (Linux x86-64 hyperthreaded 8-core @ 2.6GHz, srcdir on SSD, objdir on mechanical hard drive).\u00a0 We are not compiling 2.4x times more code than we were a year ago&#8230;or are we?\u00a0 Let&#8217;s look at some numbers.<\/p>\n<p>I looked at my mozilla-central repository for some convenient tags to pick from and found the <tt>FIREFOX_AURORA_${REV}_BASE<\/tt> set of tags.\u00a0 I started compiling with mozilla-central tip, and then with <tt>FIREFOX_AURORA_24_BASE<\/tt>, and resolved to go as far back as I could without undue fiddling with things that wouldn&#8217;t compile.\u00a0 I made it to <tt>FIREFOX_AURORA_14_BASE<\/tt> before hitting compilation errors with moz_free.\u00a0 (19 and previous required small fiddling with <tt>js\/src<\/tt> to set the right <tt>PYTHON<\/tt>, but that was easily scriptable.)\u00a0 That gives me 11 markers covering over a year of development.<\/p>\n<p>I didn&#8217;t try compiling things multiple times to see how much the numbers fluctuated.\u00a0 I didn&#8217;t attempt to control for operating system disk caches or anything like that, just <tt>hg up -r $TAG<\/tt>, generated configure, ran <tt>configure --enable-optimize --disable-debug --disable-gstreamer<\/tt> (I haven&#8217;t bothered to get my gstreamer dependencies right on my development box) in a newly-created objdir, and recorded time for <tt>make -srj20<\/tt>.\u00a0 The compiler was GCC 4.7 from Debian stable.<\/p>\n<table  style=\"border-collapse: separate; border-spacing: 3px; border: 1px solid;\" border=\"1\" cellspacing=\"2\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td>m-c tag<\/td>\n<td>real<\/td>\n<td>user<\/td>\n<td>sys<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>13m2.025s<\/td>\n<td>83m36.229s<\/td>\n<td>5m51.238s<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>13m40.359s<\/td>\n<td>87m56.302s<\/td>\n<td>6m15.435s<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>12m58.448s<\/td>\n<td>94m21.514s<\/td>\n<td>6m35.121s<\/td>\n<\/tr>\n<tr>\n<td>18<\/td>\n<td>14m21.257s<\/td>\n<td>112m42.839s<\/td>\n<td>7m36.213s<\/td>\n<\/tr>\n<tr>\n<td>19<\/td>\n<td>15m8.415s<\/td>\n<td>120m48.789s<\/td>\n<td>8m8.151s<\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>16m26.337s<\/td>\n<td>137m34.680s<\/td>\n<td>9m11.878s<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td>18m55.455s<\/td>\n<td>165m29.433s<\/td>\n<td>10m45.208s<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td>19m27.887s<\/td>\n<td>185m3.242s<\/td>\n<td>11m53.853s<\/td>\n<\/tr>\n<tr>\n<td>23<\/td>\n<td>21m9.002s<\/td>\n<td>203m46.708s<\/td>\n<td>12m51.740s<\/td>\n<\/tr>\n<tr>\n<td>24<\/td>\n<td>21m51.242s<\/td>\n<td>206m49.012s<\/td>\n<td>12m55.356s<\/td>\n<\/tr>\n<tr>\n<td>tip<\/td>\n<td>24m37.489s<\/td>\n<td>219m27.903s<\/td>\n<td>13m47.080s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Those 10-minute clobber build times were apparently the result of warm disk cache or my dreams.  Or perhaps they&#8217;re due to an older compiler; I only started using GCC 4.7 recently and I&#8217;ve done some tests that show it&#8217;s a fair amount slower than GCC 4.4.  Or maybe I was using a different build config then.  Whatever the reason, we can see that compilation times have been increasing steadily, but can we correlate that to anything?<\/p>\n<p>Let&#8217;s look at the number of C++, C, WebIDL, and IPDL source files. We include the last two because the conversion to WebIDL has been cited as a reason for increasing compilation times and IPDL because the IPDL compiler generates a number of source files as well (roughly three source files for every IPDL file). The C++ source files are split by extension; <tt>.cpp<\/tt> is the usual prefix to use inside Gecko, so separating <tt>.cpp<\/tt> and <tt>.cc<\/tt> gives some idea of how much outside C++ source code is being compiled. (Just counting source files is subject to issues, since we don&#8217;t compile everything <a href=\"http:\/\/mxr.mozilla.org\/mozilla-central\/source\/widget\/\">in <tt>widget\/<\/tt><\/a> for every platform, but we&#8217;re counting all the source files therein as if they were. This is a rough estimate.)<\/p>\n<table style=\"border-collapse: separate; border-spacing: 3px; border: 1px solid;\" border=\"1\" cellspacing=\"2\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td>m-c tag<\/td>\n<td>cpp<\/td>\n<td>cc<\/td>\n<td>c<\/td>\n<td>webidl<\/td>\n<td>ipdl<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>4060<\/td>\n<td>577<\/td>\n<td>2503<\/td>\n<td>32<\/td>\n<td>206<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>4117<\/td>\n<td>1273<\/td>\n<td>2893<\/td>\n<td>34<\/td>\n<td>213<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>4173<\/td>\n<td>1278<\/td>\n<td>2895<\/td>\n<td>38<\/td>\n<td>221<\/td>\n<\/tr>\n<tr>\n<td>18<\/td>\n<td>4468<\/td>\n<td>1405<\/td>\n<td>3123<\/td>\n<td>61<\/td>\n<td>227<\/td>\n<\/tr>\n<tr>\n<td>19<\/td>\n<td>4498<\/td>\n<td>1408<\/td>\n<td>3118<\/td>\n<td>78<\/td>\n<td>228<\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>4586<\/td>\n<td>1418<\/td>\n<td>2779<\/td>\n<td>169<\/td>\n<td>228<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td>4605<\/td>\n<td>1392<\/td>\n<td>2831<\/td>\n<td>231<\/td>\n<td>228<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td>4979<\/td>\n<td>1392<\/td>\n<td>2980<\/td>\n<td>305<\/td>\n<td>228<\/td>\n<\/tr>\n<tr>\n<td>23<\/td>\n<td>5072<\/td>\n<td>1393<\/td>\n<td>2982<\/td>\n<td>344<\/td>\n<td>231<\/td>\n<\/tr>\n<tr>\n<td>24<\/td>\n<td>5101<\/td>\n<td>1330<\/td>\n<td>2983<\/td>\n<td>413<\/td>\n<td>234<\/td>\n<\/tr>\n<tr>\n<td>tip<\/td>\n<td>5211<\/td>\n<td>1427<\/td>\n<td>3029<\/td>\n<td>436<\/td>\n<td>234<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>First things first: we have a lot of code in the tree.<\/p>\n<p>Now, there&#8217;s a couple of interesting things to point out. While there&#8217;s a lot of IPDL source files, the increase in IPDL can hardly be held responsible for the increase in compile time. So that&#8217;s one suspect out of the way. From 16 to 17, we barely increased the amount of code, but build times went <strong>down<\/strong>. This change might point to the recorded times being subject to quite a bit of variability.<\/p>\n<p>We added a lot of WebIDL files from 20 to 21 while holding everything else constant and build times went up quite a bit! But we added roughly the same number of WebIDL files from 21 to 22 along with a <strong>lot<\/strong> more code and while build times went up, they didn&#8217;t go up by the same amount: 28 minutes of user time going from 20 to 21 and ~20 minutes of user time going from 21 to 22. There are a number of reasons why this could be so: we might not be compiling all those 500 C\/C++ source files we added in 22 (ICU landed off by default in 22, so that&#8217;s ~400 files right there), the WebIDL files added in 21 might have had more of an impact, compilation-wise, the timings might fluctuate quite a bit, and so on and so forth.  And notice that we added the same number of WebIDL files again from 23 to 24 and build times <strong>hardly changed<\/strong>.  Sure, WebIDL means more files to compile.  But I don&#8217;t think they are adding a disproportionate amount of time.<\/p>\n<p>And finally, source code file counts.  We had about 7800 source code files to compile back at Aurora 15 (remember, IPDL counts as three).  We have about 10600 source files to compile now on trunk.  That&#8217;s about a 40% increase that corresponds to roughly a doubling in time to compile.  And yes, there&#8217;s also a lot of JS and other things that have been added that increase our time to compile.  But I don&#8217;t think the amount of source code is the whole story.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the past week or so, there have been a few conversations on #developers about the ever-increasing time it takes to compile Firefox.\u00a0 Compiling Firefox used to be a relatively quick affair (well, on my machine, at least) and I&#8217;ve grown dissatisfied recently with builds taking ever-longer.\u00a0 All of the aforementioned discussions have boiled down [&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\/200"}],"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=200"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}