Redesigning the HHVM JIT compiler for better performance

Visit the post for more.

Guilherme Ottoni
8 min readintermediate
--
View Original

Overview

The article discusses the redesign of the HHVM JIT compiler aimed at enhancing performance through the integration of profile-guided optimizations (PGO). It outlines the challenges faced with the initial tracelet-based design and details the multi-gear system implemented to optimize JIT compilation and improve CPU usage.

What You'll Learn

1

How to leverage profile-guided optimizations in JIT compilers

2

Why transitioning from tracelets to larger compilation regions improves performance

3

How to implement a multi-gear system for efficient profiling

Prerequisites & Requirements

  • Understanding of JIT compilation and profiling techniques
  • Experience with compiler design principles(optional)

Key Questions Answered

What are the limitations of the original HHVM JIT design?
The original HHVM JIT design faced limitations due to its reliance on tracelets, which restricted the ability to optimize across multiple execution paths and resulted in inefficiencies from repeated type checks and independent optimization of each tracelet. This approach hindered performance improvements.
How does the multi-gear system improve HHVM's performance?
The multi-gear system allows for efficient profiling by using JIT'd code to collect execution data, which enables the JIT to form larger compilation regions. This results in reduced overhead from entering and exiting tracelets and allows for more effective optimizations across the code.
What performance improvements were achieved with the HHVM JIT redesign?
The redesign of the HHVM JIT has led to a 15 percent reduction in CPU usage for running Facebook. This improvement is attributed to the integration of profile-guided optimizations and the transition to larger compilation regions.
When was the HHVM JIT redesign implemented?
The HHVM JIT redesign began in the summer of 2013, with initial profiling infrastructure and optimizations enabled by default in 2014. By spring 2015, the JIT could handle arbitrary control flow, marking a significant milestone in its development.

Key Statistics & Figures

CPU usage reduction
15 percent
This reduction was achieved through the redesign of the HHVM JIT, which integrated profile-guided optimizations.
CPU usage reduction from initial profiling mode
5 percent
This improvement was noted by the end of 2014 after enabling longer straight-line traces.

Technologies & Tools

Backend
Hiphop Virtual Machine (hhvm)
HHVM is used to execute PHP and Hack programs efficiently through JIT compilation.

Key Actionable Insights

1
Implementing profile-guided optimizations can significantly enhance JIT compiler performance.
By collecting runtime execution data, compilers can make informed optimization decisions, leading to faster code execution and reduced resource usage.
2
Transitioning from tracelet-based compilation to larger regions can eliminate inefficiencies.
This approach allows for more comprehensive optimizations, such as hoisting redundant computations and reducing type checks, ultimately improving overall performance.
3
Using a multi-gear system for profiling can minimize overhead while collecting valuable execution data.
This system allows for efficient data collection without disrupting production traffic, ensuring that performance improvements can be achieved with minimal impact.

Common Pitfalls

1
Relying solely on static compilation can lead to missed optimization opportunities.
Static compilers may struggle to gather necessary profiling data, leading to suboptimal performance. Dynamic JIT compilers, however, can seamlessly integrate profiling without disrupting user workflows.

Related Concepts

Profile-guided Optimizations
Just-in-time Compilation
Compiler Design Principles
Dynamic Vs Static Compilation