SecLern
Blog · Video lessons · 3 min

How JavaScript got fast: the compiler that rewrites your code while it runs

How JavaScript got fast: the compiler that rewrites your code while it runs

By The SecLern Team · Nov 21, 2026

Transcript

Right now, your browser is rewriting a shop's code while that code runs. And each rewrite makes it faster. That's a just-in-time compiler, and it's how JavaScript got fast. September 2nd, 2008. Google launches Chrome, with a new JavaScript engine called V8. In JavaScript, a variable can hold a number now, and text a second later. So the engine can't know in advance what your code will do. Take one line from a shop's checkout. For each item in the cart: price times quantity. First, V8 runs it in Ignition, its interpreter. It turns the line into small steps called bytecode, and walks through them one by one. Slow, but it starts instantly. While it walks, it takes notes. Every item had a price and a quantity, laid out in the same order. V8 calls that layout a shape. And both values were always numbers. Now the line runs thousands of times. It's getting hot. So V8 hands it to Sparkplug. It turns the bytecode straight into machine code, the processor's own instructions. Still hot? Then Maglev reads the notes and makes a guess: these are always numbers. Hotter still, TurboFan goes all in. It strips out almost every safety check. It keeps one tiny one: is this still the same shape? Then it just does the maths. Each tier takes longer to build. Maglev compiles about ten times slower than Sparkplug, and ten times faster than TurboFan. On one Google benchmark, TurboFan made code run about 4.35 times as fast. But a guess can be wrong. One day, a price arrives as text: nine ninety-nine, in quotes. The tiny check fails. V8 throws the fast code away and drops back to the interpreter. That's called deoptimizing. The checkout still works. It just runs slower for a while, until V8 learns the new pattern. So the fastest JavaScript is boring JavaScript. Build objects the same way. Keep each value's type the same. Then the engine's guesses keep coming true. So remember it like this. V8 watches, guesses, and backs out when it's wrong. Want to practise IT skills hands-on? Try it free at seclern.com, and follow for more.

The SecLern TeamSecLern builds practice questions, performance-based questions and browser-based hands-on labs for IT certifications.