open atlas
↑ Back to track
Browser & Frontend Runtime WEB · 03 · 01

What V8 is and why performance varies 100×

V8 turns JS source into machine code through four compilation tiers — the same function can run 100× faster or slower depending on whether V8 can keep it on the hot path.

WEB Junior ◷ 10 min
Level
FoundationsJuniorMiddleSenior

React renders 1000 rows. With stable object shapes it is nanosecond lookups and 60fps. With mixed shapes it is 10–50× slower — same code, same function, different speed because of what V8 observed.

What V8 is

V8 is the JavaScript engine inside Chrome, Edge, and Node.js. It takes JS source code and turns it into machine code the CPU executes. The same JS function can run 100× faster or slower depending on whether V8 can optimise it. A few habits — consistent object shapes, monomorphic call sites — make the difference between a 60fps animation and a janky page.

The kitchen metaphor

V8 is a kitchen with four cooks:

  • Trainee (Ignition) reads every recipe slowly but logs what was ordered.
  • Line cook (Sparkplug) cranks out fast generic versions.
  • Sous-chef (Maglev) makes specialised versions for popular dishes.
  • Head chef (TurboFan) hand-crafts a perfect dish for the most-ordered — but only if orders stay consistent. Change the order mid-bite and TurboFan tosses the dish.
V8 tiers at a glance
Tiers
4 (Ignition / Sparkplug / Maglev / TurboFan)
Ignition vs TurboFan speed
~100× slower
Megamorphic slowdown
10–50× vs monomorphic
IC monomorphic access
5–10 CPU cycles

A concrete walk-through

When you profile a slow React render, you’re often looking at this tier machinery in action — and recognising it is the difference between guessing and fixing.

Bea · Browser browser runs JS. Ignition interprets first, logging types. After thousands of calls V8 promotes to TurboFan with assumptions “arg always a number, object always has .x”. If Sven · Origin server server one day sends a string, assumptions break — deopt, fall back. The “fast” function is slow again until V8 re-learns.

React renders 1000 rows. Stable keys = monomorphic IC, nanosecond lookups. Mixed keys = polymorphic, 2–3× slower. 10+ shapes = megamorphic, 10–50× slower. Same code, vastly different speed.

Order the steps

Order the journey of a hot function through V8's tiers:

  1. 1 JS source is parsed into an AST
  2. 2 AST is converted to bytecode by the Ignition compiler
  3. 3 Ignition interprets the bytecode and records type feedback per call site
  4. 4 After thousands of calls, Sparkplug emits baseline machine code with no specialisation
  5. 5 If still hot, Maglev compiles a mid-tier optimised version using observed types
  6. 6 For the very hottest paths, TurboFan does aggressive speculative optimisation
  7. 7 If an assumption breaks at runtime, V8 deoptimizes and falls back to a lower tier
Quiz

Why does V8 use multiple compilation tiers instead of just one?

Quiz

What makes one piece of JS run 100× faster than another that does 'the same thing'?

Complete the analogy

Fill in the blank: a call site that has seen exactly one object shape is _______ and V8 generates the fastest possible machine code for it.

Why this works

Why does a dynamic language’s engine need to know types? Machine code is typed — an ADD instruction for integers is different from one for floats. V8 observes what types a call site actually sees and generates specialised code for those types. When the type changes at runtime, V8 has to throw away the specialised code and start over. That is the deoptimization cost.

Recall before you leave
  1. 01
    Name V8's four compilation tiers in order from slowest to fastest.
  2. 02
    Why does adding a new property to an object mid-way through code slow down downstream functions?
  3. 03
    What is a monomorphic inline cache and why is it the fastest IC state?
Recap

V8 is the JS engine in Chrome and Node.js. It runs code through four tiers: Ignition interprets slowly while collecting type feedback, Sparkplug emits cheap baseline machine code, Maglev optimises with observed types, and TurboFan makes aggressively optimised code for the hottest functions. A function stays on the fast tier only while object shapes — hidden classes — remain stable. One extra property added at the wrong moment changes the hidden class, degrades the inline cache from monomorphic to polymorphic or megamorphic, and costs 10–50× in throughput on that call site. The same JS function can run at 5 cycles or 500 cycles per property access depending on how consistent the shapes are. Now when you see a component that runs fine in tests but tanks in production, check whether your props objects consistently have the same shape — that is V8 telling you to fix the call site, not the algorithm.

Practice

Start at the top. Tasks go easiest → hardest: recall a fact, apply it to a case, then a senior-level stretch. Open one, attempt it, then reveal.

recallapplystretch0 of 5 done
Connected lessons
appears again in169

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.