How JavaScript works: inside the V8 engine
&gt; How to write optimized JavaScript<p>This is all sensible advice if you&#x27;re interested in writing fast-enough code, but I do find there&#x27;s a lack of material for people who want to write <i>fast</i> Javascript. Pretty much the only thing I&#x27;ve found is the post by Oz[1], though I really don&#x27;t want to have to compile Chrome.<p>For an example, I have a method in Javascript that does a mix of (integer) arithmetic and typed array accesses; no object creation or other baggage. I want it to go faster, and with effort I managed to speed it up a factor of 5. One of the things that helped was inlining the {data, width, height} fields of an ImageData object; just moving them to locals dropped time by ~40%.<p>Yet after all this effort, mostly based on educated guesses since Chrome&#x27;s tooling doesn&#x27;t expose the underlying JIT code for analysis, the code is still suboptimal. There&#x27;s a pair of `if`s that if I swap their order, that part of the code allocates. How do people deal with these issues? A large fraction of this code is still allocating, and I haven&#x27;t a clue where or why.<p>Perhaps I&#x27;m asking too much from a language without value types (srsly tho, every fast language has value types), but what I want is clearly possible: ASM.js does it! I don&#x27;t <i>really</i> want to handwrite that, though.<p>[1]: <a href="https:&#x2F;&#x2F;www.html5rocks.com&#x2F;en&#x2F;tutorials&#x2F;performance&#x2F;mystery&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.html5rocks.com&#x2F;en&#x2F;tutorials&#x2F;performance&#x2F;mystery&#x2F;</a> (E: This link is actually written from a different perspective than the one I read, but the content is the same.)