---
title: "Redesigning the HHVM JIT compiler for better performance"
description: "HHVM's JIT originally compiled tracelets, maximal type-specialized bytecode sequences formed by inspecting live VM state."
url: "https://swe.quest/articles/redesigning-the-hhvm-jit-compiler-for-better-performance-1f9d35b871d88d6a"
canonical: "https://engineering.fb.com/2016/09/22/networking-traffic/redesigning-the-hhvm-jit-compiler-for-better-performance/"
source: "Meta Engineering"
published: "2016-09-22"
difficulty: "hard"
kind: "Case study"
reading_minutes: 7
tags: ["compilers","runtimes","php","performance"]
---

# Redesigning the HHVM JIT compiler for better performance

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2016-09-22, 7 min read, Case study. Original: [https://engineering.fb.com/2016/09/22/networking-traffic/redesigning-the-hhvm-jit-compiler-for-better-performance/](https://engineering.fb.com/2016/09/22/networking-traffic/redesigning-the-hhvm-jit-compiler-for-better-performance/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [PHP](https://swe.quest/tags/php.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- JIT compilation basics ([easy posts on Compilers](https://swe.quest/tags/compilers.md?difficulty=easy))
- compiler optimization passes ([easy posts on Performance engineering](https://swe.quest/tags/performance.md?difficulty=easy))
- profile-guided optimization ([easy posts on Performance engineering](https://swe.quest/tags/performance.md?difficulty=easy))

## Keywords

HHVM, Hack, HHIR, tracelets, profile-guided optimization

## Related posts

- [Boosting the performance of virtual machines with Jump-Start](https://swe.quest/articles/boosting-the-performance-of-virtual-machines-with-jump-start-e63dbfae46ebd497.md): Meta Engineering · 2021-03-03 · Easy · 3 min read · Compilers, Runtimes & VMs, Performance engineering, Deployment, PHP
  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.
- [Meta’s Full-stack HHVM optimizations for GenAI](https://swe.quest/articles/meta-s-full-stack-hhvm-optimizations-for-genai-8b3ab67200c60012.md): Meta Engineering · 2025-05-20 · Medium · 4 min read · Runtimes & VMs, Performance engineering, Multi-tenancy, PHP, LLMs
  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%.
- [Hacklang at Slack: A Better PHP](https://swe.quest/articles/hacklang-at-slack-a-better-php-0c5b2d46ded07bab.md): Slack Engineering · 2020-04-14 · Medium · 7 min read · PHP, Type systems, Static analysis, Refactoring & migrations, Concurrency
  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.
- [Land ahoy: leaving the Sea of Nodes](https://swe.quest/articles/land-ahoy-leaving-the-sea-of-nodes-b461320cb50dc764.md): V8 · 2025-03-25 · Hard · 25 min read · Compilers, Runtimes & VMs, JavaScript, WebAssembly
  V8 is replacing Sea of Nodes in its Turbofan optimizing compiler with Turboshaft, a traditional control-flow-graph IR.
- [YJIT: Building a New JIT Compiler for CRuby](https://swe.quest/articles/yjit-building-a-new-jit-compiler-for-cruby-51c5ee3c390b2164.md): Shopify Engineering · 2021-10-14 · Easy · 6 min read · Compilers, Ruby, Runtimes & VMs, Performance engineering
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
