At Box, we've had our collective eye on the HipHop Virtual Machine (HHVM) for a while now. HHVM is Facebook's open-source PHP runtime, and it differentiates itself from from the standard PHP runtime on a key metric: speed. Whereas the standard PHP runtime is a run-of-the-mill interpreter, HHVM employs just-in-time compilation to enable significant gains in performance. Over the past few years, we've made a few different attempts at migrating our PHP codebase to run on top of HHVM. We currently have hundreds of thousands of lines of code and hundreds of contributors to our ever-growing PHP webapp, and historically they have not interacted well with HHVM. But just under a year ago, the HHVM team's growing focus on parity with the standard PHP runtime caught our attention. We decided to seriously re-evaluate HHVM, and, after a couple months spent working through github issues and runtime differences, often with Facebook’s HHVM team directly, it was clear that we were on to something big.
Many months in the making, Box is now in the process of deploying HHVM to our live webapp. The performance gains we're seeing with HHVM exceeded all expectations: in testing, our average request latency dropped by a factor of 3. This latency is measured as the time between when a request enters our infrastructure and when it leaves, which includes time spent in our PHP codebase as well as time spent talking to various backend services.
The road to HHVM wasn't without bumps or unexpected detours, though. After using Apache to run our PHP codebase for 7 years, our architecture and processes had ossified around the standard PHP runtime. Additionally, since PHP is a massive and dynamic language, we ran into use cases that HHVM had not used or built for. Replacing these components and contributing bug fixes back to HHVM as our architecture and codebase surfaced them were significant tasks.
The migration also required a revamp of our deployment system. Since HHVM is a JIT compiler, it introduces a requirement to run new code a few times before all of the performance gains can be realized. Thus, when deploying new instances of HHVM, they have to 'warm up' and cycle through code before going live. This detail, however small, necessitated an internal operational change in how we deploy new code.
Almost every request that touches Box goes through our PHP codebase, so the speed increase is felt almost everywhere: our webapp, our sync client, our mobile applications, and our API. Box also stands to make very large savings in infrastructure costs over the years. We see this deployment as an important step for Box and one that will continue to optimize our service, as long as our PHP webapp exists, we will continue to see performance benefits from HHVM.