<story><title>How JavaScript works: inside the V8 engine</title><url>https://blog.sessionstack.com/how-javascript-works-inside-the-v8-engine-5-tips-on-how-to-write-optimized-code-ac089e62b12e</url></story><parent_chain></parent_chain><comment><author>Veedrac</author><text>&amp;gt; How to write optimized JavaScript&lt;p&gt;This is all sensible advice if you&amp;#x27;re interested in writing fast-enough code, but I do find there&amp;#x27;s a lack of material for people who want to write &lt;i&gt;fast&lt;/i&gt; Javascript. Pretty much the only thing I&amp;#x27;ve found is the post by Oz[1], though I really don&amp;#x27;t want to have to compile Chrome.&lt;p&gt;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%.&lt;p&gt;Yet after all this effort, mostly based on educated guesses since Chrome&amp;#x27;s tooling doesn&amp;#x27;t expose the underlying JIT code for analysis, the code is still suboptimal. There&amp;#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&amp;#x27;t a clue where or why.&lt;p&gt;Perhaps I&amp;#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&amp;#x27;t &lt;i&gt;really&lt;/i&gt; want to handwrite that, though.&lt;p&gt;[1]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.html5rocks.com&amp;#x2F;en&amp;#x2F;tutorials&amp;#x2F;performance&amp;#x2F;mystery&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.html5rocks.com&amp;#x2F;en&amp;#x2F;tutorials&amp;#x2F;performance&amp;#x2F;mystery&amp;#x2F;&lt;/a&gt; (E: This link is actually written from a different perspective than the one I read, but the content is the same.)</text></comment>
<story><title>How JavaScript works: inside the V8 engine</title><url>https://blog.sessionstack.com/how-javascript-works-inside-the-v8-engine-5-tips-on-how-to-write-optimized-code-ac089e62b12e</url></story><parent_chain></parent_chain><comment><author>cm2187</author><text>I was wondering, given that 90% of the javascript in browsers must be standard libraries (jquery, bootstrap &amp;amp; co) wouldn&amp;#x27;t it make sense for google to hash the source code for every published version of these libraries, compile those statically using full optimisation and ship the binaries as part of their updates to the browser, so that you only have to compile the idiosyncratic part of the code?</text></comment>