HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance for PHP applications.
During these last past months, HHVM and the upcoming PHP 7 version have engaged in an epic battle to become the fastest PHP engine. At Symfony we are thrilled because this fierce competition will ultimately benefit all of us.
Our HHVM compatibility journey started on December 2013, when Joseph Bielawski added HHVM to the list of tested PHP engines on Travis CI (see commit). Shortly after, Fabien made the first code change to improve HHVM compatibility:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Add support for HHVM in the getting of the PHP executable
// @see https://github.com/symfony/symfony/pull/9882
class PhpExecutableFinder
{
// ...
public function find()
{
if (defined('HHVM_VERSION') && false !== $hhvm = getenv('PHP_BINARY')) {
return $hhvm;
}
// ...
}
}
That was the first code change, but tens of other changes followed. Some of them were tricky, like the one solved by Christophe Coevoet in the 10,000th Symfony Pull Request:
1 2 3 4 5 6 7 8 9 10
// src/Symfony/Component/Console/Application.php
// HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is
// a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
$width = $this->getTerminalWidth()
? $this->getTerminalWidth() - 1
: (defined('HHVM_VERSION')
? 1 << 31
: PHP_INT_MAX)
;
The hard work made by the Symfony Community always put us at more than 99% HHVM compatibility according to their project compatibility charts. The last needed push to achieve the 100% milestone for Symfony 2.3 was led by Nicolas Grekas in the PR 15,146
This last pull request fixed all the issues found on the Debug, DependencyInjection, Filesystem, Form, HttpFoundation, Process and Routing components. However, due to some HHVM issues or lacking PHP features, in some cases our only choice was to skip the test entirely:
1 2 3
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM behaves differently in this test case.');
}
After these changes were merged, Travis finally displayed a green result for Symfony 2.3 tests run on HHVM:
Now it's time to celebrate, but soon we'll get right back to work in order to achieve 100% HHVM compatibility for the rest of maintained Symfony branches.
Good to hear! But when running a Symfony application, not just the framework itself needs to be tested against a new engine like HHVM - all the other libraries used also need to be tested.
A overview for this can be found at my site: http://hhvm.h4cc.de/graphs/ You can also upload a composer.lock files to check HHVM compatibility of your application.
Nice. This notice should be updated here as well somehow: http://hhvm.com/frameworks/
If some tests are skipped, can we say we achieve 100% of compatibility?
This is very nice but in my opinion the article should explain a bit the benefits of this effort.
A screenshot with the result of tests is showed. This information says nothing for me. It's a figure with no context.
@Hassan there are some test skipped because of HHVM errors, issues, bugs or lacking features. Once HHVM fix those issues, we'll fix our tests.
@Felix the benefit is that you can run Symfony 2.3 on HHVM engine, which is orders of magnitude faster than doing it in PHP 5.3 or 5.4 engines. In recent PHP engines the performance differences are not that abysmal.
For the reader (no personal offence @Javier, thank you very much for this article!):
This is not "in some cases" that our only choice was to skip the test entirely. This is the ONLY case that our only choice was to skip the test entirely.
100% hhvm compat is 100% honest. We did not skip any single tests because of errors, issues nor bugs. The single missing "feature" of hhvm is this one: strict notices. Kudos to hhvm for what they did: parity is close enough so that the delta can be handled in exactly the same way as we handle deltas between PHP versions.
If anyone felt offended by what I wrote about HHVM issues, please note that at the moment there are more than 800 reported issues in the official HHVM repository. I said this in a positive way and I personally think that having lots of issues is normal for a big and popular project (Symfony has hundreds of reported issues too and I think that's good).
And regarding the skipped tests and lacking features, I considered in that phrase all the code related to Symfony, including Monolog, Twig, Doctrine, etc. If you look for in the Symfony source code, you'll find lots of skipped tests and even some lacking features due to the different behavior of HHVM.
Thanks for the precisions @Javier!
And BTW, for the reader again, you'll be happy to know that just a few days after this post, Symfony now enforces 100% HHVM for all branches!
The problem is that Symfony is either compatible with HHVM or PHP, not both! This makes it hard to use PHP-FPM failback on production.