{"id":296,"date":"2010-06-25T05:04:51","date_gmt":"2010-06-24T18:04:51","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=296"},"modified":"2010-06-25T05:15:54","modified_gmt":"2010-06-24T18:15:54","slug":"dont-be-stupid","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2010\/06\/25\/dont-be-stupid\/","title":{"rendered":"Don&#8217;t be stupid"},"content":{"rendered":"<p>Good compilers are complicated, and generating good code is hard.\u00a0 Clever<br \/>\noptimisations play their part, but it can be equally important to not do<br \/>\nthings that are stupid.<\/p>\n<p>Back in March I noticed this awful code begin generated by TraceMonkey for<br \/>\naccess-fannkuch.js, one of the SunSpider benchmarks:<\/p>\n<pre> ld16 = ld sp[-152]\r\n sti sp[-152] = ld16\r\n ld17 = ld sp[-128]\r\n sti sp[-128] = ld17\r\n ld18 = ld sp[-88]\r\n sti sp[-88] = ld18\r\n ld19 = ld sp[-80]\r\n sti sp[-80] = ld19\r\n sti sp[-72] = addxov1\r\n ld20 = ld sp[-64]\r\n sti sp[-64] = ld20\r\n ld21 = ld sp[-48]\r\n sti sp[-48] = ld21\r\n sti sp[-32] = ld15\r\n ld22 = ld sp[-8]\r\n sti sp[-8] = ld22\r\n j -&gt; label1<\/pre>\n<p>A number of the trace fragments compiled for that benchmark ended similarly.<br \/>\nI filed <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=551885\">a bug<\/a> and investigated a little at the time but didn&#8217;t understand<br \/>\nthe responsible code well enough to fix it.<\/p>\n<p>This week I took another look, and was glad that I did.\u00a0 Thanks to a better<br \/>\nunderstanding of the responsible code, I was able to fix it with only a <a href=\"http:\/\/hg.mozilla.org\/tracemonkey\/rev\/03876a6eba5a\">29<br \/>\nline patch<\/a> (10 lines of which were comments).\u00a0 Even better, it turns out<br \/>\nthis fix not only affected the small number of egregiously stupid cases such<br \/>\nas the one above;\u00a0 it also removed a lot of redundant stores that were less<br \/>\nobvious.\u00a0 The net result was about a 2% speedup for the SunSpider benchmark<br \/>\nsuite and 3% for the V8 benchmark suite.\u00a0 That&#8217;s a satisfying patch!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good compilers are complicated, and generating good code is hard.\u00a0 Clever optimisations play their part, but it can be equally important to not do things that are stupid. Back in March I noticed this awful code begin generated by TraceMonkey for access-fannkuch.js, one of the SunSpider benchmarks: ld16 = ld sp[-152] sti sp[-152] = ld16 [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[467],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/296"}],"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=296"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}