{"id":8,"date":"2008-03-07T01:08:10","date_gmt":"2008-03-07T01:08:10","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/03\/07\/low-level-optimization-decays-with-time\/"},"modified":"2008-03-07T19:00:34","modified_gmt":"2008-03-08T00:00:34","slug":"low-level-optimization-decays-with-time","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/03\/07\/low-level-optimization-decays-with-time\/","title":{"rendered":"Low Level Optimization Decays With Time"},"content":{"rendered":"<p>Did you know that hand-optimized assembler is slower then allegedly &#8220;slow&#8221; languages, say, Lisp or JavaScript?  It&#8217;s true, if you wait long enough.<\/p>\n<p>Imagine you have found some old hand-tuned Lisp code, and a hand-tuned <http:\/\/en.wikipedia.org\/wiki\/PDP-1>PDP-1<\/a> assembly language version.  If you executed both programs today, using a modern Lisp interpreter and a modern PDP-1 emulator, the Lisp code would perform much better.  That&#8217;s because it could take advantage of all the improvements in Lisp interpreters and computers since the 1960&#8217;s, while the PDP-1 code would be held back by trade-offs made long ago to appease obsolete hardware.<\/p>\n<p>I expect that ultimately JavaScript will outperform contemporary SSE code, because hardware inevitably becomes obsolete over time.<\/p>\n<p>When assembly code becomes obsolete, you are stuck with two slow options.  Use obsolete hardware to execute the code, or emulate your obsolete hardware on a new computer (since computers keep getting faster, emulation will become the fastest choice).  Meanwhile the high-level code will still be executable, <em>and<\/em> able to take advantage of all subsequent hardware improvements.<\/p>\n<p>Some x86 instructions are already obsolete; by which I mean they give worse performance then more common instructions.<\/p>\n<blockquote><p>Assembly\/Compiler Coding Rule 31. (ML impact, M generality) Avoid using complex instructions (for example, enter, leave, or loop) that have more than four \u00b5ops and require multiple cycles to decode. Use sequences of simple instructions instead. <\/p><\/blockquote>\n<p>&#8212; <a href=\"http:\/\/www.intel.com\/design\/processor\/manuals\/248966.pdf\">Intel\u00ae64 and IA-32 Architectures Optimization Reference Manual<\/a><\/p>\n<p>You could say that this is all academic, because in half a century the code you wrote today will be irrelevant, and I would agree.  PDP-1 vs Lisp was hypothetical hyperbole, show that <strong>the benefits of low-level optimization decrease the longer the code is in use<\/strong>, because the advantages compared to high-level code decrease over time.  <\/p>\n<p>What really drove this home for me was <a href=\"http:\/\/www.apple.com\/pr\/library\/2005\/jun\/06intel.html\">Apple&#8217;s switch from PPC to x86<\/a>.  Suddenly all the <a href=\"http:\/\/en.wikipedia.org\/wiki\/AltiVec\">AltiVec<\/a> code I&#8217;d ever written was obsolete.  If someone bought a new Mac, my AltiVec code would be emulated, and slower then unchanged (but recompiled) C code!  I could have <a href=\"http:\/\/developer.apple.com\/documentation\/Performance\/Conceptual\/Accelerate_sse_migration\/migration_intro\/chapter_1_section_1.html\">reused existing AltiVec code to create SSE code<\/a>, but then <em>I would be stuck doing optimization work every time a sufficiently new computer came out<\/em>.<\/p>\n<p>Algorithmic-level optimization holds it&#8217;s value over time; low-level optimization does not.  However, software is such a rapidly-changing environment that a short-term investment can still make a hell of a lot of sense.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that hand-optimized assembler is slower then allegedly &#8220;slow&#8221; languages, say, Lisp or JavaScript? It&#8217;s true, if you wait long enough. Imagine you have found some old hand-tuned Lisp code, and a hand-tuned PDP-1 assembly language version. If you executed both programs today, using a modern Lisp interpreter and a modern PDP-1 emulator, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,10],"tags":[],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-macosx","category-programming","category-tips"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}