BT

How Facebook Redesigned the HHVM JIT Compiler for Performance

| by Sergio De Simone Follow 14 Followers on Oct 06, 2016. Estimated reading time: 1 minute |

In the Summer of 2013, Facebook engineers started a major redesign of the HHVM JIT compiler that brought an overall 15% reduction of CPU usage on Facebook’s web servers. Facebook engineer Guilherme Ottoni has recently described how Facebook achieved that result by backing profile-guided optimizations (PGO) into their JIT compiler.

Profile-guided optimization is a technique that aims to use runtime profiling, such as identifying parts of the code that are executed more frequently, to improve code generation. PGO is particularly well-suited for integration in dynamic and JIT compilers given the integrated nature of the compiler and the runtime environment.

Facebook engineers focused on two main goals: using profile information to optimize decisions that are made at compilation time and to help the compiler identify larger type-specialized compilation regions, i.e., regions where generated code can be optimized for a given known type, thus avoiding the cost of type checks. To make this possible, the HHVM JIT compiler had to learn how to translate arbitrary code regions instead of just tracelets, which are very basic type-specialized blocks that are independently translated to machine code. Tracelets do not grow arbitrarily, since by their definition tracelets end whenever the type for an input to the block cannot be determined, or when the JIT compiler cannot determine the direction of a branch.

The first step taken by Facebook engineers to generalize tracelets was to assemble several of them together based on profiling information. By doing this, they could reduce the overhead of entering and exiting different tracelets, and additionally implement more advanced cross-tracelet optimizations, such as hoisting loop-invariant computations out of loops.

Building larger regions out of basic tracelets had the advantage of not violating any assumptions in the existing JIT optimizer and backend, which were tightly designed around that concept. In a second phase, though, Facebook engineers started a major redesign of those components to be able to handle regions with arbitrary control flow. This effort, completed by the spring of 2015, significantly improved JIT compilation performance by reducing CPU usage by 15%, thus trebling the improvement gained in the first phase.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT