liveBook · Manning

Code compilation

As explained in JavaScript in Depth

The process of translating code from one form into another, often from source text into lower-level executable form.

A function’s performance can change dramatically without changing its source: V8 compiles code in stages, investing more work in functions that run repeatedly. The pipeline moves from lazy parsing to bytecode, baseline machine code, and finally highly optimized machine code. section 6.6.2

The pipeline responds to execution frequency and observed types:

  • Lazy parsing pre-parses a function for syntax, then builds its full syntax tree only when the function is called. section 6.6.2
  • Ignition compiles every parsed function into bytecode, a simplified instruction set for execution. section 6.6.2
  • Sparkplug and Maglev provide baseline machine-code compilation, while TurboFan produces highly optimized machine code. section 6.6.2
  • Feedback slots record type information for instructions; changing argument types can invalidate that feedback and require new instructions. section 6.6.2

Why repeated calls get faster

For getTotal(items), measurements over 20 million element reads improve from 986.12 milliseconds under Ignition to 25.38 milliseconds under TurboFan. Each tier changes the execution cost rather than the function’s source behavior. section 6.6.2

Figure 6.1 The V8 Compilation Pipeline

The pipeline diagram makes the progression from parsing through optimized machine code immediately navigable. section 6.6.2

How JavaScript in Depth covers it

How deep it goes
Descends to parsing stages, bytecode instructions, feedback slots, and tier benchmarks, but not compiler implementation internals beyond these mechanisms.
Examples
Uses an addition function, generated bytecode, a repeated getTotal benchmark, and a V8 pipeline diagram.
What you can do after
Evaluate/understand how call frequency and argument types influence V8 compilation and observed performance.
How it connects
Connects lazy parsing with abstract syntax trees, bytecode with interpretation, and type feedback with machine-code optimization.

Also explained in

Compare how 8 books explain code compilation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.