Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 6 min read Deep dive hardMaster

Optimizing JavaScript Standard Library Functions in JSC

JavaScriptCore speeds up Function.prototype.toString by stacking several general optimizations that together reduce a call like f.toString() to a constant string. The result is cached on the function object, watchpoints let the DFG/FTL speculate that f and f.toString never change, an intrinsic replaces the generic call with a FunctionToString instruction that loads the cached value inline with a C++ fallback, and the abstract interpreter constant-folds the load when the receiver is known. The walkthrough also contrasts C++ and JS-implemented builtins, noting that native builtins can't be inlined but intrinsics can still emit their fast paths.

Assumes: JIT compilation tierscompiler intermediate representationsJavaScript prototype semantics

Related posts

  • Bun v0.1.9

    Bun mediumAdept

    Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making `ptr()` in `bun:ffi` 6-10x faster and `TextEncoder.encodeInto` 1.5-5x faster. To get there, Bun extended DOMJIT to accept Typed Array arguments and to declare more kinds of side effects. Bun now code-generates C++ binding classes and ABI-checked Zig bindings from JavaScript class definitions, an approach inspired by WebIDL, replacing most use of the JSC C API. Other changes include a more reliable, lower-CPU event loop on Linux, about 20% faster `Bun.serve` through better `Headers` handling, native `buffer` and `process` modules, and numerous crash fixes.

  • How the Cinder JIT’s function inliner helps us optimize Instagram

    Meta Engineering hardMaster

    Cinder, Instagram's open-source CPython fork, ships a method-at-a-time JIT that lowers bytecode through HIR, SSA, LIR and register allocation to native code, removing interpreter dispatch and stack overhead. Because type information is only available within a single function, generic operations like BinaryOp and VectorCall often can't be specialized. The new function inliner splices known call targets (identified via guarded global loads) into the caller's CFG. It does this by SSA-ifying the callee separately, splitting the block, rewriting LoadArg and Return into Assigns, adding shadow-frame bookkeeping, and cleaning the CFG. Later type inference and optimization passes can then specialize or even constant-fold the inlined code.

  • Compile and run C in JavaScript

    Bun mediumAdept

    Bun v1.1.28 adds experimental `cc` in `bun:ffi`, which uses TinyCC to compile, link and relocate C in memory and generates inline wrappers that convert between JavaScriptCore values and C primitives with no dynamic dispatch. It is pitched as an alternative to N-API addons, which need node-gyp builds or prebuilt platform matrices and cost 7–15ns per call versus 2ns for the JavaScriptCore C++ API, and to WebAssembly, which cannot make system calls and must copy data across its isolated memory. Benchmarks show about 5ms to compile a small file and roughly 2ns of per-call overhead over native C. It suits glue code for C and system libraries such as ffmpeg or the macOS Keychain, not large projects needing Clang/GCC-level optimization.

  • Speculative Optimizations for WebAssembly using Deopts and Inlining

    V8 hardMaster

    V8 in Chrome M137 adds speculative call_indirect inlining and deoptimization support for WebAssembly, using runtime call-target feedback gathered by the Liftoff baseline compiler so TurboFan can inline up to four likely callees behind cheap instance and target checks. When an assumption fails, the Deoptimizer serializes the optimized frame into a FrameDescription, rebuilds the matching Liftoff stack frame and resumes in baseline code mid-function. This lets the optimizer drop generic slow paths that would otherwise block further optimization. The gains matter most for WasmGC languages like Dart, Java and Kotlin: over 50% average speedup on Dart microbenchmarks and 1–8% on realistic applications, with one microbenchmark dropping from 675 ms to 90 ms.

  • How we made JSON.stringify more than twice as fast

    V8 hardMaster

    V8 more than doubled JSON.stringify throughput on the JetStream2 json-stringify-inspector benchmark by adding an iterative, side-effect-free fast path that skips the general serializer's defensive checks. Supporting changes include templatizing the stringifier on one-byte vs two-byte strings, SIMD and SWAR scanning for escapable characters, and a fast-json-iterable flag on hidden classes that lets keys be copied without checks. Numbers are now converted with Dragonbox instead of Grisu3, and output goes to a segmented Zone-allocated buffer to avoid realloc-and-copy. The fast path ships in V8 13.8 (Chrome 138) and applies only without replacer/space arguments, custom toJSON, indexed properties or ConsString-like strings.

The quest for software engineering knowledge.

Look:
Layout: