TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How JavaScript compilers work

95 pointsby wx196almost 12 years ago

6 comments

rayineralmost 12 years ago
The terminology in the article is somewhat idiomatic: &quot;After the Directed Flow Graph (DFG) or syntax tree has been generated the compiler can use this knowledge to perform further optimisations prior to the generation of machine code. Mozilla’s IonMonkey and Google’s Crankshaft are examples of these DFG compiler.&quot;<p>&quot;DFG&quot; usually refers to some sort of dependence graph. What IonMonkey and Crankshaft have is a traditional CFG (control flow graph) in SSA form. That means the code is represented as a set of straight line code paths (basic blocks) connected edges in a graph representing possible control-flow transitions. The instructions are in SSA form, which means that each variable is assigned only once and pseudo-instructions called &quot;phi instructions&quot; are used to merge results when a basic block is accessible from multiple predecessors blocks, both of which might assign the same variable. A &quot;syntax tree&quot; is different yet. It&#x27;s a higher level representation that preserves the syntactic structure of the code. For example, it represents loops and &quot;if&quot; statements as nested elements in the tree. Translation to a CFG throws away most of that information (e.g. reducing loops to simply control flow edges in the CFG).<p>For a (relatively) approachable set of materials on the subject, see: <a href="http:&#x2F;&#x2F;www.cs.rice.edu&#x2F;~keith&#x2F;512&#x2F;2011&#x2F;Lectures" rel="nofollow">http:&#x2F;&#x2F;www.cs.rice.edu&#x2F;~keith&#x2F;512&#x2F;2011&#x2F;Lectures</a>. I also highly recommend Cooper &amp; Torczon&#x27;s &quot;Engineering a Compiler&quot; (2d Ed.) In a world of CS researchers that can&#x27;t write an English sentence to save their lives, Keith Cooper and Linda Torczon&#x27;s work is a paragon of clear prose. (Their lab at Rice is where Cliff Click got his PhD, and if you&#x27;ve read his work on the JVM, you know that he too has a talent for explaining complicated concepts in plain English.)
评论 #5846507 未加载
评论 #5846102 未加载
deweerdtalmost 12 years ago
The 4 parts:<p>- The JavaScript family tree: <a href="http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-1-the-javascript-engine-family-tree&amp;#x2F" rel="nofollow">http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-1-the-...</a>;<p>- How compilers work: <a href="http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-2-how-javascript-compilers-work&amp;#x2F" rel="nofollow">http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-2-how-...</a>;<p>- JavaScript compiler strategies: <a href="http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-3-javascript-compiler-strategies&amp;#x2F" rel="nofollow">http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-3-java...</a>;<p>- The future for JavaScript: <a href="http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-4-the-future-for-javascript&amp;#x2F" rel="nofollow">http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;06&#x2F;the-race-for-speed-part-4-the-...</a>;
评论 #5845356 未加载
WalterBrightalmost 12 years ago
Source for a JavaScript compiler implemented in the D programming language:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;DigitalMars&#x2F;DMDScript" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DigitalMars&#x2F;DMDScript</a>
评论 #5846806 未加载
leetroutalmost 12 years ago
So I have question I&#x27;m sure someone here is smart enough to answer- simply put, does ASI affect compilation speed?<p>In my head I would imagine that a compiler would expect to find semicolons as statement terminators but would have to reprocess a block if validation failed and try to figure out where the semicolons should be, and therefore ASI would slow down compilation (vs a file with all semicolons in place).
评论 #5846948 未加载
评论 #5845703 未加载
评论 #5845798 未加载
评论 #5845728 未加载
acqqalmost 12 years ago
A very nice text with the nice code examples is:<p><a href="http:&#x2F;&#x2F;mrale.ph&#x2F;blog&#x2F;2012&#x2F;06&#x2F;03&#x2F;explaining-js-vms-in-js-inline-caches.html" rel="nofollow">http:&#x2F;&#x2F;mrale.ph&#x2F;blog&#x2F;2012&#x2F;06&#x2F;03&#x2F;explaining-js-vms-in-js-inli...</a>
评论 #5846854 未加载
frozenportalmost 12 years ago
How is the JavaScript JIT different from the Java JIT?