Look what guys at Facebook did for PHP performance

Care to share?

Wow! performance benchmarks shown on http://hhvm.com looks incredible! Performance of PHP applications beter 4x,5x times? This is possible with HHVM (Hip Hop Virtual Machine).

For very complex systems as Magento use of compilation and PHP Virtual Machine (rather than standard interpreter) could increase performance in hundret of percents. Compatibility could be (small for now) issue – You could check this bellow.

Hip Hop was created a few years ago – as Facebook contribution to PHP community. This compiler produces pseudo-binary code (bytecode) from PHP scripts – which code is interpreted then by JIT (Just In Time) compiler and executed. This method of optimization changing PHP nature from interpreter – to compiled language. No IO overload is used to load hundreds of PHP files; hardware optimizations could be used; code could be optimized for desired CPU architecture. It works very similar to Java/VM or .NET/CLR.

JIT compiled pseudo-binary code works a lot faster:

  • no interpreting phase is needed;
  • a lot less files are used to run application – everything is compiled into one package – result is lower I/O load,
  • code optimization could be done during compilation (as in standard in other compiled/JIT languages- e.g C# or Java).

HHVM is step further. HHVM brings with it many benefits over HPHPc (first HH compiler). There is near full support for the entire 5.4 PHP language (including the create_function() and eval() functions)

Could I really use it?

HHVM is FCGI compilant – which means You could use it with Apache, nginx and other popular servers. The webserver is in charge of handling all the intricate details of the HTTP protocol. HHVM is in charge of what it does best, running PHP code blazingly fast. HHVM FastCGI server uses asynchronous I/O. This means that an I/O thread will never block waiting on a single connection. Instead, system routines such as select() are used to monitor activity on multiple connections at once.

You could see some ass-kicking performance benchmarks on offical HHVM blog post.

Compatibility

Compatibility was a huge problem with HH from the begining. For example PHP functions – “eval()”, “create_function()” didn’t work at all. This (and other incompatibilities) causes problems with existing code.

More optimizations  and a lot more compatibility were applied to solve this. HHVM team has recently 3 weeks performance and parity lock down. 

As official blog says:

Going into lockdown, the team knew that awesome performance alone would not suffice in making HHVM a viable PHP runtime to be used out in the wild. It actually had to run real, existing PHP code reliably. So we made that a first class work item (as it will continue to be into 2014). Our first step into improving PHP parity was to look at Github, see whichPHP projects were being used by many people (via their “star” rating) and make sure their unit tests would run successfully on HHVM.

On picture above (from offical HHVM blog) You could see that now popular frameworks – like Symfony2 and applications – Magento2(!) are compilant with HHVM.

This is great news. We plan to test HHVM with existing line of Magento (1.x) and the new one in next few weeks.

Published January 16, 2014