Turbocharging V8 with mutable heap numbers
V8 eliminated a performance cliff in JetStream2's async-fs benchmark caused by a custom Math.random whose `seed` lives in a ScriptContext slot. Every update to the seed allocated a new immutable HeapNumber, and the integer bitwise math was compiled as floating-point. V8 now tracks slot types (constant, SMI, HeapNumber, Int32, other) and lets a context slot own a mutable HeapNumber that is updated in place, storing raw Int32 values when they stay in range. Optimized code depends on the slot type staying stable and deoptimizes if it changes, and the change gives about a 2.5x speedup on async-fs and about 1.6% on the overall JetStream2 score.
Related posts
- V8 release v6.9 · V8
V8 easyNoviceV8 v6.9 embeds built-in functions directly into the binary on x64, so all Isolates share one copy instead of each holding up to 700 KB on its own heap. Across the top 10k sites this cut median V8 heap size by 9%, and 10% of sites saved 3.7 MB or more. Liftoff, a new baseline WebAssembly compiler, speeds startup by over 10×. DataView methods were reimplemented in Torque and inlined by TurboFan to match TypedArray speed, and concurrent, incremental and parallel WeakMap processing roughly halves Mark-Compact GC pauses, with a linear-time fallback replacing worst cases that could take seconds. The release also adds Array.prototype.flat and flatMap.
- Celebrating 10 years of V8 · V8
V8 easyNoviceV8 grew over ten years from a secret project started in 2006 on a Danish farm into a JavaScript and WebAssembly engine supporting eight instruction sets, embedded by both Chrome and Node.js. Key milestones include the Irregexp regex engine, the Crankshaft and later TurboFan optimizing compilers, the Ignition interpreter, the incremental and then Orinoco parallel/concurrent garbage collectors, idle-time GC, code caching, Liftoff, and Spectre mitigations. V8 Bench scores rose 4× from 2008 to 2018, with dips from the initial ES2015 features and Spectre mitigations. The curve flattens after 2013 because the team shifted from synthetic micro-benchmarks to real-world performance, and Speedometer 1 scores rose another 4× over 2013–2018.
- How Bun supports V8 APIs without using V8 (part 2)
Bun hardMaster
Bun emulates V8's memory layout on top of JavaScriptCore so that precompiled native addons, which inline V8 functions assuming specific pointer layouts, keep working. The approach uses tagged pointers (Smis or heap pointers), a small set of static fake Map objects with instance types at the expected offset, and 24-byte Handles in a handle scope that store the tagged pointer, map pointer and JSCell pointer side by side, avoiding separate allocations outside the GC. Walkthroughs of Local, HandleScope, Number::New/Value and objects with internal fields show how JSC values are presented to V8-compiled code.
- The V8 Sandbox
V8 hardMasterThe V8 Sandbox is a lightweight, in-process software sandbox that isolates the V8 heap so memory corruption from engine bugs cannot spread to the rest of the renderer process. It is now included in Chrome's VRP as of Chrome 123. V8 exploits usually stem from 2nd-order logic bugs, often in JIT compilers, which neither Rust nor memory tagging can prevent. The sandbox therefore replaces raw pointers and 64-bit sizes on the heap with 40-bit offsets from a 1TB reserved region, plus a pointer-table indirection for external objects. Overhead is about 1% on Speedometer and JetStream, and the design is testable through a memory-corruption API and a sandbox-violation detection mode used for fuzzing.
- Static Roots: Objects with Compile-Time Constant Addresses
V8 hardMasterV8's static roots place the read-only heap at the start of every pointer-compression cage and generate it deterministically, so core objects like `undefined` get compressed addresses known at compile time (e.g. `undefined` is always 0x61). A generated static-roots.h file, cached in the repo and regenerated only when the read-only heap layout changes, lets libv8's C++ and the builtins compiler embed these constants instead of loading from a global roots array. Grouping related objects also turns checks such as "is string" or "is truthy" into address range comparisons. Shipped in Chrome 111, the change gave roughly a 1% Speedometer 2 gain on M1.