Details on how Microsoft Edge browser internally implements JIT compilation for JavaScript code

Posted: (EET/GMT+2)

 

If you have ever wondered how Microsoft Edge ("Spartan") handles JavaScript execution under the hood, it might be interesting to take a brief look at its JIT compilation pipeline. Edge's JavaScript engine, Chakra, has a surprisingly sophisticated multi-tier architecture that tries to balance fast startup with high-performance optimized code.

At a high level, Chakra performs these steps:

  • Parsing and bytecode generation: your JavaScript is first parsed into an abstract syntax tree and converted into bytecode for quick interpretation.
  • The interpreter warms things up: Chakra begins by running the code in an interpreter. This keeps startup costs low and avoids compiling functions that run only once.
  • Simple JIT: once functions become "hot", Chakra compiles them to native machine code using a lightweight JIT tier.
  • Full JIT: if the function continues to run and Chakra can gather enough type information, the engine applies heavier optimizations in a second compilation tier.

If you want a concrete example of how browsers move code across multiple tiers, Google published a security-related whitepaper describing their research tooling around JIT behavior:

https://github.com/google/p0tools/blob/master/JITServer/JIT-Server-whitepaper.pdf

Even though this paper is not about Chakra specifically, it helps you understand how modern JavaScript engines aggressively collect runtime information, speculate on types, and recompile code when needed. Chakra follows a conceptually similar approach.

If you've ever seen JavaScript suddenly run much faster "after a few iterations", now you know why.