Skip to content

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

Meta Engineering 7 min read Case study hardMaster

Redesigning the HHVM JIT compiler for better performance

HHVM's JIT originally compiled tracelets, maximal type-specialized bytecode sequences formed by inspecting live VM state. Tracelets end at unknown types or branches, which causes repeated type guards, register/memory shuffling at boundaries, and blocks cross-tracelet optimizations such as loop-invariant hoisting. Facebook redesigned it as a multi-gear system: a profiling gear reuses the tracelet JIT with counters after type guards to gather block frequencies and types, and an optimizing gear recompiles hot paths as larger regions with arbitrary control flow. Getting there meant rewriting most optimization passes, which had relied on acyclic tracelets. Longer traces alone cut webserver CPU by about 5% in 2014, and the full redesign cut it by about 15%. Profiles also drive code layout, method dispatch, partial inlining, guard relaxation and array specialization.

Related posts

  • Boosting the performance of virtual machines with Jump-Start

    Meta Engineering easyNovice

    Jump-Start cuts JIT warm-up overhead in HHVM by having a small slice of the fleet collect profiling data during Facebook's phased rollout. That data is shared with the remaining servers, so they skip the profiling compile-and-run step. Profile data from the ~2% of servers restarted in phase C2 is reused by the servers restarted in phase C3. Deployed across Facebook's data centers, it reduces HHVM warm-up overhead by 54.9% and, because the profiling can be more thorough, also improves steady-state performance by 5.4%.

  • Meta’s Full-stack HHVM optimizations for GenAI

    Meta Engineering mediumAdept

    Meta moved GenAI inference traffic, which is long-running, I/O-heavy and latency-sensitive, onto a dedicated HHVM web tenant with its own runtime tuning, cutting latency by 30%. The isolated tier raises the usual 30-second request timeout and runs about 1,000 worker threads per host, sized by dividing host memory by the per-request memory limit, instead of a couple hundred. It also seeds the JIT cache with Jump-Start profiles from the main web tier and runs dummy warm-up requests to pre-fill config and service-discovery caches. Shadow traffic keeps the JIT cache covering code paths that open up later through real-time feature gating.

  • Hacklang at Slack: A Better PHP

    Slack Engineering mediumAdept

    Slack moved its PHP 5 backend to HHVM in 2016 for speed and stayed for Hack, whose static type checker reports type errors as code is typed rather than at runtime. Gradual typing let the team migrate incrementally from partial to strict mode. Shapes, typed dicts with known and optional keys, are used for database rows, decoded JSON and functions with many options. Async/await with concurrent blocks adds I/O concurrency without threads, while dropping PHP compatibility in HHVM 4.0 improved the language at the cost of the Packagist ecosystem and constant upgrade work.

  • Land ahoy: leaving the Sea of Nodes

    V8 hardMaster

    V8 is replacing Sea of Nodes in its Turbofan optimizing compiler with Turboshaft, a traditional control-flow-graph IR. The JavaScript backend and the entire WebAssembly pipeline already run on it, and Maglev is taking over the JS frontend. After more than a decade with Sea of Nodes, the team found its theoretical benefits largely unrealized for JavaScript. Checks, loads and stores keep most nodes pinned to the effect or control chains, memory operations rarely float, and the graphs are hard for engineers to read, debug and lower. Explicit control and effect chains make lowerings error-prone, while a CFG stays closer to both the source code and the emitted assembly.

  • YJIT: Building a New JIT Compiler for CRuby

    Shopify Engineering easyNovice

    YJIT is a new JIT compiler built inside CRuby by Shopify and GitHub engineers, based on Basic Block Versioning, and aimed at real-world workloads like Rails where the GCC-based MJIT has struggled. After about a year it delivers speedups over the interpreter of 20% on railsbench, 39% on liquid template rendering and 37% on activerecord, with near-peak performance after one iteration. It passes CRuby's ~30,000 tests and the CI suites of Shopify Core and GitHub, and is slated to merge into Ruby 3.1. Only about 79% of railsbench instructions currently run in YJIT, and planned CRuby changes include object shapes, cheaper type tagging, finer-grained constant caching, a lighter calling convention, and rewriting C runtime methods in Ruby to enable inlining.

The quest for software engineering knowledge.

Look:
Layout: