← All articles
Languages & Runtimes

How V8 runs your JavaScript inside Node.js

How V8 works in Node.js: lazy parsing, bytecode, JIT tiers, hidden classes, inline caches and deopts, with commands you can run on Node.js 22.

V8, the JavaScript engine inside Node.js, does not compile your code to machine code before it runs. It starts every function in an interpreter, compiles only the functions that run often, and bets that they keep seeing the same kinds of values. Knowing how V8 works in Node.js tells you which performance advice still holds, because some well-known rules stopped being true years ago and one became true again in 2024.

Watch V8 compile a function, then throw the code away

Every command in this article targets Node.js 22. The printed output comes from one run of Node.js v22.17.0 (V8 12.4) on one machine, so your addresses and timings will differ. Where Node.js 23 and later behave differently, a note says so.

Save this as fib.js:

function fib(n) {
  return n < 2 ? n : fib(n - 1) + fib(n - 2);
}

const start = performance.now();
fib(30);
console.log(`fib(30) took ${Math.round(performance.now() - start)} ms`);

console.log('now with 25.5');
fib(25.5);
console.log('done');

The first call passes only whole numbers, and the second passes a fraction. Run the file with two V8 flags that print what the engine does with each function:

node --trace-opt --trace-deopt fib.js

Before you read the output, predict two things. Does fib ever run as machine code? And what happens to that code when fib receives 25.5?

Here is the output, with memory addresses replaced by …:

[marking … <JSFunction fib …> for optimization to TURBOFAN, ConcurrencyMode::kConcurrent, reason: hot and stable]
[compiling method … <JSFunction fib …> (target TURBOFAN), mode: ConcurrencyMode::kConcurrent]
[completed compiling … <JSFunction fib …> (target TURBOFAN) - took 0.028, 1.471, 0.019 ms]
[completed optimizing … <JSFunction fib …> (target TURBOFAN)]
fib(30) took 16 ms
now with 25.5
[bailout (kind: deopt-eager, reason: not a Smi): begin. deoptimizing … <JSFunction fib …>, … <Code TURBOFAN>, opt id 0, bytecode offset 2, …]
[marking … <JSFunction fib …> for optimization to TURBOFAN, ConcurrencyMode::kConcurrent, reason: hot and stable]
[compiling method … <JSFunction fib …> (target TURBOFAN), mode: ConcurrencyMode::kConcurrent]
[completed compiling … <JSFunction fib …> (target TURBOFAN) - took 0.005, 1.128, 0.014 ms]
[completed optimizing … <JSFunction fib …> (target TURBOFAN)]
done

fib did not start as machine code. V8 ran it in its interpreter until it was “hot and stable”, then compiled it on a background thread with TurboFan, V8’s optimizing compiler. The compile took about 1.5 ms, and the rest of fib(30) ran the compiled code.

The compiled code assumed that n is always a Smi, V8’s small integer that is stored inside the pointer itself, with no object on the heap. Official 64-bit Node.js builds store 32-bit integers this way, while Chrome stores 31-bit ones, because Chrome compresses its pointers and Node.js does not by default. 25.5 is not a Smi, so a check in the compiled code failed at the n < 2 comparison, which the trace reports as offset 2.

V8 then made a deoptimization, or deopt for short. It dropped the compiled code and continued the same call in the interpreter, with no error and the same result. A moment later it compiled fib again, this time for numbers that may have a fraction.

The same fib(30) runs at very different speeds depending on which compilers V8 may use. Run fib.js with flags that turn compilers off, and compare the fib(30) line:

node fib.js
node --no-opt fib.js
node --jitless fib.js
Command What V8 may use fib(30)
node fib.js Every compiler about 15 ms
node --no-opt fib.js Every compiler except TurboFan about 40 ms
node --jitless fib.js The interpreter only about 92 ms

These numbers come from three runs of each command on one machine with Node.js v22.17.0, and yours will differ. In V8 12.4, --no-opt is an alias for --no-turbofan. --jitless also prints a warning that it turned WebAssembly off.

The middle row shows that something besides TurboFan makes fib more than twice as fast as the interpreter alone. A later section names it.

Rule: V8 compiles a function only after it has run for a while, and drops the compiled code when the values it assumed change.

How V8 works in Node.js, and what Node.js adds around it

This section answers which part of the node process runs your JavaScript, and which part does everything else.

V8 runs JavaScript and owns the heap your objects live in. It also owns the microtask queue that holds Promise callbacks, but Node.js decides when that queue is emptied. Node.js sets V8’s microtask policy to explicit and calls runMicrotasks() itself in lib/internal/process/task_queues.js. The order in which Node.js runs callbacks is the subject of How Node.js works: the event loop, so this article stays inside V8.

V8 alone has no timers, no files and no require. You can see this from Node.js, because vm.runInNewContext() runs code in a new global scope that Node.js adds nothing to:

node -p "require('node:vm').runInNewContext('[typeof setTimeout, typeof require, typeof process, typeof Promise]').join(' ')"
undefined undefined undefined function

Promise is part of the JavaScript language, so V8 provides it. setTimeout, require and process come from Node.js.

Node.js adds two layers under its JavaScript API. libuv is the C library that owns the event loop and the thread pool that runs file system work, dns.lookup() and some crypto and zlib work. A binding is a C++ function that Node.js exposes to its own JavaScript, and it receives its arguments as V8 values (src/README.md).

For example, fs.readFileSync(path, 'utf8') in lib/fs.js calls binding.readFileUtf8(). The C++ side, in src/node_file.cc, calls libuv’s uv_fs_open() with no callback, which runs it synchronously on the JavaScript thread. A later section measures what one crossing from JavaScript into C++ costs.

Node.js’s own JavaScript has to set up process, require and the rest before your file runs. Node.js does not run those setup scripts at every start. It loads a startup snapshot, a copy of the V8 heap saved after the scripts ran when the binary was built (lib/internal/bootstrap/node.js). You can turn it off with --no-node-snapshot, which src/node_options.cc marks as a debug-only option:

/usr/bin/time -p node -e 0
/usr/bin/time -p node --no-node-snapshot -e 0

On one machine with Node.js v22.17.0, real was 0.06 seconds with the snapshot and 0.10 seconds without it.

Then your own file loads. The Node.js docs say a CommonJS module is wrapped in a function, and they show the wrapper as a string.

Node.js 22 builds no string unless a package has patched Module.wrap. Instead, wrapSafe() in lib/internal/modules/cjs/loader.js asks V8 to compile your file as the body of a function with five parameters, listed in src/node_contextify.cc. Save this as args.js and run node args.js:

console.log(arguments.length, typeof require, typeof __dirname);
5 function string

exports, require, module, __filename and __dirname are the five arguments of that function. From here on, V8 does the work: it parses the function, runs it and compiles the parts that get hot.

V8 skips the functions you have not called yet

Parsing and compiling every function before the first line runs would slow down startup, and much of the code in a program never runs (V8 blog, 2019). So V8 delays most of that work. Save this as lazy.js:

function used() { return 1; }
function unused() { return 2; }
used();

Bytecode is the compact instruction format that V8’s interpreter runs, and --print-bytecode prints it for every function V8 compiles:

node --print-bytecode lazy.js | grep -E 'function: (used|unused)'
[generated bytecode for function: used (… <SharedFunctionInfo used>)]

unused never got bytecode. V8’s preparser read its body only to check the syntax and to note which outer variables it uses, and it built nothing for it. A skipped function is parsed in full and compiled the first time it is called. Since V8 6.3, a function is preparsed at most once, however deeply it is nested (V8 blog).

The syntax check is complete, so an error in a function you never call still stops the file. Save this as early.js and run it:

function never() { let x; let x; }
console.log('ran');
SyntaxError: Identifier 'x' has already been declared

V8 makes one exception and compiles a function eagerly, at once, when the function expression is wrapped in parentheses, such as (function () { … }). Such functions are usually called right away. The V8 team advises against adding parentheses only to get this, because it compiles more code up front (V8 blog).

Ignition runs bytecode and records what it sees

Ignition is V8’s interpreter, the one that ran fib before TurboFan took over. Save this as add.js:

function add(a, b) {
  return a + b;
}

let sum = 0;
for (let i = 0; i < 1e6; i++) sum = add(sum, i);
console.log(sum);

Print the bytecode for add only:

node --print-bytecode --print-bytecode-filter=add add.js
[generated bytecode for function: add (… <SharedFunctionInfo add>)]
Bytecode length: 6
Parameter count 3
Register count 0
Frame size 0
   23 S> … @    0 : 0b 04             Ldar a1
   32 E> … @    2 : 3b 03 00          Add a0, [0]
   36 S> … @    5 : ae                Return

The output continues with tables that are not needed here. Ignition’s bytecodes name the registers they read and write, and most also use the accumulator, an implicit register that needs no operand (V8 blog, 2016). Ldar a1 loads b into the accumulator, Add a0, [0] adds a to it, and Return returns the accumulator. Because the accumulator is implicit, add fits in six bytes.

The [0] in Add a0, [0] is a slot number in the function’s feedback vector, the per-function record of what each operation has seen (V8 blog, 2019). When Add runs, it notes the types of its inputs in slot 0, such as “both were Smis”. Property loads such as o.x get slots too. TurboFan reads these slots later to decide what to assume, which is how fib came to assume Smis.

Feedback vectors take memory, so a function does not get one on its first call. In V8 12.4 it gets one after it has used a budget of 8 times its bytecode length (flag-definitions.h). The next section explains how that budget is counted. Until then, the function’s calls record nothing.

V8’s JIT tiers, and the three that Node.js 22 ships

V8 has one interpreter and three JIT compilers, which compile bytecode to machine code while the program runs (V8 tiering docs). A function starts in Ignition and moves up a tier when it has run enough.

Tier Kind How it compiles Deoptimizes In Node.js 22.9 and later 22.x releases
Ignition Interpreter Does not compile; runs bytecode Not applicable Yes
Sparkplug Baseline compiler One pass over the bytecode, no optimization Never Yes
Maglev Optimizing compiler About 10 times slower than Sparkplug and 10 times faster than TurboFan Yes No
TurboFan Optimizing compiler Slowest; the most optimized code Yes Yes

Sparkplug explains the 40 ms row. It translates bytecode to machine code in one linear pass, keeps Ignition’s stack frame layout and does no real optimization, so it compiles fast and never deoptimizes (V8 blog, 2021). Turn it off as well with node --no-opt --no-sparkplug fib.js, and fib(30) took about 92 ms on the same machine, as slow as --jitless.

Maglev is a mid-tier optimizing compiler. It uses feedback and deoptimizes like TurboFan, and its compile speed sits between Sparkplug and TurboFan (V8 blog, 2023). Node.js 22.0.0 turned it on (nodejs/node#51360). Node.js 22.9.0 turned it off again, after crashes and wrong JavaScript behavior with V8 12.4 (nodejs/node#54384).

Since 22.9.0, Maglev is not even compiled into the binary, so --maglev does nothing. Check your build:

node -p process.config.variables.v8_enable_maglev

On Node.js v22.17.0 this prints 0.

Node.js 23 and later: Maglev is on by default on x64, arm and arm64 (configure.py in v24.0.0). Its budget is lower than TurboFan’s, so a hot function reaches Maglev first. On Node.js v24.22.3 (V8 13.6), node --trace-opt fib.js prints these lines for fib, shortened, before fib(30) took 12 ms:

text [compiling method … <JSFunction fib …> (target MAGLEV), mode: ConcurrencyMode::kConcurrent] [completed compiling … <JSFunction fib …> (target MAGLEV) - took 0.000, 0.209, 0.002 ms] [compiling method … <JSFunction fib …> (target TURBOFAN_JS), mode: ConcurrencyMode::kConcurrent] [completed compiling … <JSFunction fib …> (target TURBOFAN_JS) - took 0.063, 7.275, 0.049 ms]

Maglev compiled fib in about 0.2 ms, and TurboFan replaced that code soon after. After the deopt on 25.5, fib went through Maglev again before TurboFan. The trace also lists some of Node.js’s own functions, such as normalizeString, because they run hot during startup.

The tier-up flags are named “invocation count”, but they are not call counters. V8 12.4 multiplies each flag by the function’s bytecode length to get a budget, in InterruptBudgetFor() in tiering-manager.cc. The budget is used up at each return and at each jump back to the top of a loop (interpreter-generator.cc). You can print the multipliers:

node --v8-options | grep 'default: --invocation-count'
        type: int  default: --invocation-count-for-feedback-allocation=8
        type: int  default: --invocation-count-for-maglev=400
        type: int  default: --invocation-count-for-maglev-osr=100
        type: int  default: --invocation-count-for-turbofan=3000
        type: int  default: --invocation-count-for-osr=800
        type: int  default: --invocation-count-for-early-optimization=20

The source sets the OSR value to 500. A Maglev OSR setting raises it to 800 at runtime, even in this build without Maglev.

Because loops use up the budget too, one call with a long loop can be enough. OSR (on-stack replacement) switches a function to optimized code in the middle of a running loop, without waiting for the call to return. In add.js, the top-level loop runs once, in one call, and node --trace-opt add.js shows it compiled this way:

[compiling method … <JSFunction (sfi = …)> (target TURBOFAN) OSR, mode: ConcurrencyMode::kConcurrent]

The function without a name is the module function that holds the loop.

Rule: A function tiers up when it has run enough bytecode for its size, not after a fixed number of calls.

Objects built the same way share a hidden class

Note: The next examples use --allow-natives-syntax, which turns on V8’s internal test functions such as %HaveSameMap(). They are internal and unstable: V8 can rename or remove them in any version, and a file that uses them is a syntax error without the flag. Use them to look inside V8, never in code you ship.

Save this as shapes.js:

const a = { x: 1, y: 2 };
const b = { x: 3, y: 4 };
const c = { y: 5, x: 6 };

console.log('a and b:', %HaveSameMap(a, b));
console.log('a and c:', %HaveSameMap(a, c));

All three objects have the properties x and y. Predict the two lines, then run node --allow-natives-syntax shapes.js:

a and b: true
a and c: false

Every object points to a hidden class, a description of its layout that lists its named properties and where in the object each one is stored (V8 blog, 2017). V8’s source and tools call a hidden class a “map”, which is where %HaveSameMap() gets its name.

Adding a property moves an object from one hidden class to the next. These steps form a transition tree that all objects share, so objects that add the same properties in the same order end with the same hidden class (V8 docs). a and b add x and then y. c adds y first, takes another branch of the tree, and ends with a different hidden class.

So “x is stored at this position” is true for every object with that hidden class. Code that has checked the hidden class once can then read x with one memory load.

Arrays get a second label. An elements kind records what an array’s indexed elements hold: only Smis, any numbers, or any values (V8 blog, 2017). Each comes in a packed variant and a holey variant for arrays with gaps. An array only moves toward the more general kind.

Save this as elements.js and run it with --allow-natives-syntax:

const arr = [1, 2, 3];
console.log('start:      ', %HasSmiElements(arr));
arr.push(4.5);
console.log('after 4.5:  ', %HasDoubleElements(arr));
arr.pop();
console.log('after pop():', %HasDoubleElements(arr));
start:       true
after 4.5:   true
after pop(): true

pop() removed the 4.5, but the array still stores its elements as doubles. The same post says that you rarely need to think about elements kinds. It also says the difference between packed and holey is usually too small to measure.

Inline caches turn feedback into fast property loads

The feedback slot for o.x holds more than types. An inline cache (IC) is the cache at one property access in your code. The first time o.x runs, V8 looks up x the slow way. It then stores the object’s hidden class in that slot, with a small handler such as “load the field at word offset 3” (V8 docs).

On later runs, V8 compares the object’s hidden class with the stored one, and on a match it runs the handler.

An IC has states that only move forward:

  • Monomorphic: the site has seen one hidden class.
  • Polymorphic: it has seen two to four hidden classes, and checks each one in turn.
  • Megamorphic: it has seen more than four. V8 stops recording hidden classes at that site and uses one hash table shared by all code on that thread.

The limit of four is --max-valid-polymorphic-map-count in V8 12.4. You can watch one site go through the states. Save this as ic.js:

function getX(o) {
  return o.x;
}

const objects = [{ x: 1 }, { x: 1, a: 1 }, { x: 1, b: 1 }, { x: 1, c: 1 }, { x: 1, d: 1 }];
for (const o of objects) getX(o);
node --log-ic --logfile=ic.log --no-logfile-per-isolate --no-lazy-feedback-allocation ic.js
grep '^LoadIC' ic.log | grep ',x,'
LoadIC,0x3b4bb5fc1bc0,72290,2,12,0,1,0x3b4bc290d059,x,,
LoadIC,0x3b4bb5fc1bc0,72305,2,12,1,P,0x3b4bc290d111,x,,
LoadIC,0x3b4bb5fc1bc0,72317,2,12,P,P,0x3b4bc290d181,x,,
LoadIC,0x3b4bb5fc1bc0,72328,2,12,P,P,0x3b4bc290d231,x,,
LoadIC,0x3b4bb5fc1bc0,72341,2,12,P,N,0x3b4bc290d301,x,,

After the line and column (2,12) come the old state and the new state. The site goes from uninitialized (0) to monomorphic (1), then polymorphic (P). The fifth hidden class makes it megamorphic (N). The flag --no-lazy-feedback-allocation is needed because five calls are not enough to give getX a feedback vector, and without one nothing is logged.

Optimizing compilers bet on feedback and check every bet

TurboFan turns feedback into fast paths with a check in front of each one. A monomorphic site becomes one hidden-class check and one field load. A polymorphic site becomes a short switch over its hidden classes (V8 docs). After a + b has seen only Smis, it becomes two Smi checks and an integer add that checks for overflow (Benedikt Meurer, 2017).

The check that failed in fib.js was one of these Smi checks. When a check fails, V8 deoptimizes. Current V8 has two kinds (V8 docs):

  • An eager deoptimization happens when a check inside the running optimized code fails, such as not a Smi in fib.js or wrong map for an unexpected hidden class. Execution continues in Ignition at the current bytecode.
  • A lazy deoptimization happens when V8 invalidates optimized code while a call to it is still on the stack, waiting for another function to return. A changed prototype or an overwritten constant field can do this. The function leaves optimized code when that other function returns.

Older articles list a third kind, “soft”. V8 removed it in 2022 because it behaved the same as eager (V8 commit 1ff685d8b1).

V8 does not get stuck in a loop of optimizing and deoptimizing, for three reasons:

  1. Feedback only widens. After the deopt in fib.js, slot 0 recorded a non-Smi number, so the next TurboFan compile handled fractions.
  2. A change to any IC delays the next optimization, to 500 times the bytecode length in V8 12.4 (V8 tiering docs).
  3. A deopt can mark its check so the compiler does not make the same failed guess again (V8 docs).

Before 2017, V8 gave up optimizing a function after 10 deoptimizations. It removed that limit because TurboFan should no longer cause such loops (V8 commit 1c02987d2d).

Rule: A deopt is V8 correcting a guess, and the next compile includes what it learned.

What tiers, deopts and hidden-class changes cost

Each tier trades compile time for faster code. Against Ignition alone on the JetStream benchmark suite, V8 measured Sparkplug at 45% faster and TurboFan at 4.35 times faster (V8 blog, 2023).

Compiling every function with TurboFan would spend that compile time on code that runs once. Lazy parsing skips even the bytecode for code that never runs. Memory counts too, because feedback vectors take a large share of the heap (V8 blog, 2019).

A deopt throws away compile work, and the function runs in a lower tier until V8 compiles it again. In fib.js the second compile took about 1.1 ms on a background thread. The V8 team describes occasional deopts as cheap and expected (V8 blog, 2023). The lasting cost is what the feedback looks like afterwards, because a site that has gone megamorphic stays megamorphic.

To see that cost, save this as poly.js. It times one property-load site that sees 1, 2, 4, 8 or 32 hidden classes:

function makeObjects(nShapes, count) {
  const out = [];
  for (let i = 0; i < count; i++) {
    const o = { x: i };
    o['p' + (i % nShapes)] = 0; // a different extra key per shape
    out.push(o);
  }
  return out;
}

function run(nShapes) {
  // a new load site per run, so feedback from one run does not reach the next
  const sumX = new Function('objs', 'let s = 0; for (let i = 0; i < objs.length; i++) s += objs[i].x; return s;');
  const objs = makeObjects(nShapes, 10000);
  for (let i = 0; i < 200; i++) sumX(objs); // warm up
  const t = process.hrtime.bigint();
  for (let i = 0; i < 2000; i++) sumX(objs);
  return Number(process.hrtime.bigint() - t) / 2000 / 10000; // ns per load
}

for (const n of [1, 2, 4, 8, 32]) console.log(`${String(n).padStart(2)} shapes: ${run(n).toFixed(2)} ns/load`);

In two runs of node poly.js on one machine, one hidden class cost about 1.5 to 1.7 ns per load. Two to four cost about 2.2 to 2.7 ns, roughly 1.5 times as much. Eight or 32 cost about 6.0 to 6.3 ns, roughly 2.5 times the polymorphic cost. The times include the loop, and your numbers will differ.

delete has a larger cost. Dictionary mode means an object’s properties move into a hash table that its hidden class no longer describes, so inline caches lose their fast path (V8 blog, 2017). Since V8 12.2, deleting any named property puts the object in dictionary mode (V8 commit 389ea9be7d). Save this as delete.js and run it with --allow-natives-syntax:

const deleted = { x: 1, y: 2 };
delete deleted.y;

const cleared = { x: 1, y: 2 };
cleared.y = undefined;

console.log('after delete:   ', %HasFastProperties(deleted));
console.log('after undefined:', %HasFastProperties(cleared));
after delete:    false
after undefined: true

Dictionary mode is the right choice for an object used as a dictionary, with keys added and removed all the time. For that data a Map is clearer anyway.

Crossing from JavaScript into C++ costs more than a JavaScript call. Node.js’s contributor docs call the overhead of calling C++ functions high (adding-v8-fast-api.md). So V8 offers Fast API calls, C++ functions that optimized code calls directly with plain C++ types such as int32_t and double.

Fast API calls work only from TurboFan code, and only when the argument types match. In Node.js 22, Buffer.compare() has a fast version (src/node_buffer.cc). Save this as fastapi.js:

const a = Buffer.from('0123456789abcdef');
const b = Buffer.from('0123456789abcdeg');
const N = 2e7;

function run() {
  let s = 0;
  for (let i = 0; i < N; i++) s += Buffer.compare(a, b);
  return s;
}

run(); // warm up so TurboFan optimizes the loop
const t = process.hrtime.bigint();
const s = run();
console.log(`${(Number(process.hrtime.bigint() - t) / N).toFixed(1)} ns/call (check ${s})`);
node fastapi.js
node --no-turbo-fast-api-calls fastapi.js

On one machine, a call took about 34 ns with fast calls and about 80 ns without them. Each call also includes Buffer.compare()‘s argument checks in JavaScript. The same contributor doc warns that a function whose work costs far more than the call gains little, so the crossing matters for small calls made very often.

Running without the JIT, and reusing compiled code

--jitless stops V8 from creating executable memory while the program runs (V8 blog, 2019). Only Ignition runs, regular expressions are interpreted, and WebAssembly is unavailable. It exists for platforms that do not let ordinary apps write executable memory, such as iOS, smart TVs and game consoles, and to reduce attack surface. Node.js marks the flag experimental.

The cost depends on how much of the time is JavaScript. V8 measured about 6% slower on a YouTube app for TVs and about 80% slower on a benchmark of JavaScript tools. For a loop that is all JavaScript, save this as cpu.js:

const t = process.hrtime.bigint();
let s = 0;
for (let i = 0; i < 1e8; i++) s = (s + i * i) % 1000003;
console.log(`${(Number(process.hrtime.bigint() - t) / 1e6).toFixed(0)} ms (s=${s})`);

node cpu.js took 1101 ms and node --jitless cpu.js took 5144 ms on one machine, about 4.7 times as long. We would use --jitless only where the platform requires it or where attack surface matters more than CPU time.

The other direction is to keep compiled code between runs. The compile cache stores V8’s code cache for your modules on disk and reuses it on the next start (Node.js docs). V8’s code cache holds serialized bytecode, not optimized machine code (V8 blog).

NODE_COMPILE_CACHE=.node-cache node app.js

The environment variable arrived in Node.js 22.1.0, and module.enableCompileCache() in 22.8.0. Both stopped being experimental in 25.4.0. The 22.1.0 release post reports loading the TypeScript compiler going from about 130 ms to about 80 ms. The cache works only with the Node.js version that wrote it, the first run is slower, and code coverage can be less precise in functions loaded from the cache.

A user-land startup snapshot is a startup snapshot of the heap that your own setup code builds. node --snapshot-blob snap.blob --build-snapshot entry.js runs entry.js and saves the heap, and node --snapshot-blob snap.blob starts from it (Node.js docs).

Building snapshots stopped being experimental in 24.13.1 and 25.4.0, though the docs still label --snapshot-blob experimental. The entry must be one script, so you bundle your modules into it first. A snapshot loads only on the same Node.js version, architecture and platform, and otherwise Node.js exits with status 1.

What changed between Node.js 20 and Node.js 26

In the release data, each Node.js major kept one V8 version apart from patch updates (nodejs.org/dist/index.json):

Node.js First release V8 Maglev on by default
20 April 2023 11.3 No
22 April 2024 12.4 Only in 22.0 to 22.8
24 May 2025 13.6 Yes
25 October 2025 14.1 Yes
26 May 2026 14.6 Yes

Turboshaft is a new back end for TurboFan, built on a control-flow graph. Since Chrome 120 (December 2023) it runs TurboFan’s CPU-independent back-end phases, so Node.js 22 already uses it (V8 blog). By March 2025 it ran the whole JavaScript back end (V8 blog). Traces still name the tier TURBOFAN in Node.js 22 and TURBOFAN_JS in Node.js 24.

Smaller changes since 2024 that affect what you see in traces:

  • V8 12.2 (January 2024, Node.js 22 and later): deleting the last-added property no longer keeps the object fast.
  • V8 12.8 and later (Node.js 23 and later): Maglev does not compile a catch block that has never run. The first throw into it causes one lazy deopt (V8 commit 40a900106c).
  • V8 13.6 (Node.js 24): after some lazy deopts, V8 re-optimizes sooner (V8 commit e8e91e0943).

Two pieces of advice are still repeated but no longer match V8:

  • “try/catch prevents optimization.” That was true of Crankshaft, the compiler before TurboFan. TurboFan, which replaced it in V8 5.9 in 2017, was built to optimize all of ES5 and newer JavaScript (V8 blog, 2017). V8’s docs now describe a try block as free until something throws (V8 docs).
  • “Deleting the last-added property keeps the object fast.” That was true from V8 6.0 to 12.1. Since 12.2 every delete of a named property leads to dictionary mode, as delete.js shows.

Cheat sheet: what V8 does with your code

The main points of this article, in the order they appear:

  • Who does what: V8 runs your JavaScript and owns the heap. Node.js and libuv do the I/O, timers and require.
  • Lazy parsing: a function you never call gets no bytecode, but a syntax error inside it still stops the file.
  • Ignition first: every function starts as bytecode, and its feedback vector records the types and hidden classes each operation sees.
  • Tier-up: a function moves up a tier after it has run enough bytecode for its size, not after a fixed number of calls. A long loop can tier up in the middle of one call (OSR).
  • Tiers by version: Node.js 22 uses Ignition, Sparkplug and TurboFan. Node.js 23 and later add Maglev between Sparkplug and TurboFan.
  • Hidden classes: objects that add the same properties in the same order share a hidden class. A different order gives a different one.
  • Inline caches: a property access is fastest with one hidden class and a little slower with two to four. With five or more it goes megamorphic, which cost about 2.5 times the two-to-four case in poly.js.
  • Deopts: when a bet fails, V8 drops the compiled code, continues in Ignition and compiles again with wider feedback. An occasional deopt is normal.
  • delete: since V8 12.2, deleting any property puts the object in dictionary mode. Set the property to undefined on hot objects instead.
  • try/catch: it does not stop optimization. That advice dates from Crankshaft, before 2017.
  • Measure first: use --cpu-prof to find the hot functions, then --trace-deopt on those functions only.

How to use this on your own hot paths

Measure before you change code. node --cpu-prof app.js writes a .cpuprofile file that you open in Chrome DevTools, and the flag is stable since Node.js 22.4.0. For the few functions the profile shows as hot, run node --trace-deopt app.js | grep bailout and read the reasons. The cost is noise, because traces are long and V8 flags have no stability guarantee between versions.

Keep hidden classes consistent on hot paths. Create an object in one place, with all its properties in the same order:

// excerpt: every user object gets the same properties in the same order
function makeUser(row) {
  return { id: row.id, name: row.name, score: row.score ?? 0 };
}

Start numeric fields as numbers, not null, so V8 does not have to change how it stores the field later (V8 blog, 2019). The cost is that varied data, such as the nodes of a syntax tree, does not fit one hidden class. Forcing it into one makes the code harder to read for a small gain.

On hot objects, set a property to undefined instead of using delete. The cost is that the property still exists, so 'y' in o stays true and Object.keys(o) still lists it. If code depends on the key being gone, build a new object without it.

Leave alone what the profiler says is fine. Polymorphic sites cost little in poly.js, and an occasional deopt in a trace is V8 working as designed.

Next, run node --cpu-prof on a service you own, then run --trace-deopt and look for wrong map on its three hottest functions.

Further reading:

If you want the next article on Node.js internals when it comes out, subscribe to the newsletter.

Comments

No comments yet. Ask a question or share what worked for you.

Leave a comment

Write a comment before you post.

Enter your name.

Never shown on the site.

Enter an email address like name@example.com.

Comments are checked before they appear. Fields marked * are required.

Keep reading

Related articles

  • Languages & Runtimes

    How Node.js Works: The Event Loop

    Two rules that let you predict the order of setTimeout, setImmediate, process.nextTick and Promise callbacks in Node.js, with code you can run to check each one.