Login   Register  
PHP Classes
elePHPant
Icontem

PHP Developer working for Google Launches New PHP Compiler - PHP Classes blog

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP Developer working...   Post a comment Post a comment   See comments See comments (1)   Trackbacks (0)  
<< Previous: PHP 5.7 New Features ...

Author: Manuel Lemos

Posted on:

Categories: PHP Performance, News

Recently it was launched a new PHP compiler named Recki-CT that generates native machine code that can outperform the same PHP code run by Zend Engine or Facebook HHVM.

Read this article to learn more about this new PHP compiler, how it works and the plans for its future.




Contents

What is Recki-CT?

How does Recki-CT work?

How Fast is Recki-CT?

Future Developments

Conclusion


What is Recki-CT?

Anthony FerraraRecki-CT (Recki Compiler Toolkit) is a project launched by Anthony Ferrara, a long time PHP developer that has joined Google recently as a developer advocate.

Despite he is working at Google, Recki-CT is not really part of his developer advocate work. It is something that he does in the 20% of his work time that Google allows their employees to work on projects of their choice. So, this should not be understood as an official Google project, despite the copyright notices mention Google and contributors need to sign a CLA (Contributor License Agreement).

Recki-CT is a project totally written in PHP itself. It parses PHP code and generates native assembly code as result of the compilation of the PHP code.

How does Recki-CT work?

Anthony was contacted and he was so kind to help clarifying how Recki-CT works and how it can compile PHP code that achieves such impressive performance results.

Basically, Recki is a PHP library that takes some PHP code, parses it to build an Abstract Syntax Tree (AST) using Nikita Popov's PHP-Parser

Then Recki-CT analyses the syntax tree to perform some optimizations. The result is compiled code into an intermediary representation text format. That code is passed to Joe Watkins' JIT-FU extension that emits native code using the libjit library.

The resulting machine code can be executed by calling it like you call a closure function in PHP.

How Fast is Recki-CT?

In terms of speed we need to see it from two points of view. The first is the compilation step. This is not a fast step, not only because it is implemented with PHP code, but also because the parsing, analysis and optimization tasks tend to be slow due to the complexity of such tasks.

Therefore Recki-CT caches the compiled code to avoid taking too much time recompiling the same code over and over again.

As for the actual compiled code, according to the benchmarks published in an article in Anthony's blog, in some cases the resulting code outperforms Zend Engine version included in PHP 5.5, as well HHVM 3.2.

Here are some results taken from that article. Notice that in some cases the tests fail because they run code that is not yet supported by Recki-CT.

php 5.5Recki-CThhvm 3.2hippy-cqb
simple()139.633571.000008.304477.656938.35018
simplecall()38.99476FAIL1.325521.00000FAIL
simpleucall()54.020411.000003.524391.5107247.91090
simpleudcall()52.145341.000003.759361.4161447.55259
mandel()21.262491.000002.033722.11208FAIL
mandel_typed()23.165531.000002.111282.092123.00061
mandel2()24.432751.000002.577041.87802FAIL
mandel2_typed()23.799891.000002.901051.571937.11054
ackermann(7)35.048701.000002.27557103.45436621.72526
ary(50000)1.39338FAIL1.000004.47888FAIL
ary2(50000)1.26952FAIL1.000002.28231FAIL
ary3(2000)5.96015FAIL1.709971.00000FAIL
fibo(30)39.484401.000001.6064716.40883FAIL
hash1(50000)1.70014FAIL1.000003.27314FAIL
hash2(500)2.23648FAIL1.000001.30044FAIL
heapsort(20000)3.67800FAIL1.000004.96699FAIL
matrix(20)4.38364FAIL1.0000037.72782FAIL
nestedloop(12)29.249241.000002.914593.07568FAIL
sieve(30)10.95413FAIL1.000004.95152FAIL
strcat(200000)1.48186FAIL2.060031.00000FAIL
jumpapaluza(50, 50)11.677461.092401.481921.00000FAIL
bitapaluza1(21)63.333571.0000021.396551.46851FAIL
bitapaluza2(18)21.833461.000006.197152.59416FAIL

Future Developments

Currently Recki-CT does not support all code constructs of PHP. This will be improved over time.

Right now the the last step of compiling to machine code is done at runtime. So Anthony plans to move this step to the actual compilation step and have the resulting machine code cached too.

Another interesting possibility is to take advantage of the built-in AST support that is being included in PHP 7, thanks also to the contribution of Nikita Popov to the PHP 7 development. That would make the actual compilation step faster, as the AST support in Recki-CT is currently is being implemented in PHP code.

Conclusion

2014 has been an awesome year for PHP in terms of important developments that bring extra performance to PHP.

First we had Facebook HHVM and the Hack language bringing amazing features and speed improvements. Then we had the reaction of Zend to bring other speed improvements to PHP 7.

More recently we had Recki-CT, as well Hippy-VM which is another fast implementation of the PHP language using the PyPy technology.

Recki-CT seems to bring some additional interesting aspects when compared to other solutions. One is that it can be used to compile just parts of your PHP code. This means that you do not need to compile all your PHP application to take advantage of its capabilities to speedup parts of your PHP applications that are slow.

Another aspect is that since it is mostly done in PHP, it can run with the Zend Engine based PHP, or even with HHVM or Hippy-VM, as long as the JIT-FU extension is available. So, it is not really an alternative to other PHP engines, but rather something that can boost your PHP code performance further.

One side aspect that is not related to PHP performance is the fact that compiling the code to machine code, this solution may be used eventually to ship compiled code without giving away the source code.

Although it was not the original intention of the project, this aspect may interest developers that are willing to sell their PHP work without giving away the source code.

All these aspects make the future of PHP even more promising and exciting than it already is. Congratulations to Anthony Ferrara and all others that are bring such amazing improvements to PHP.

What do you think? Do you feel is there anything else important that PHP needs to make it even more exciting? Post a comment to tell what you think.


You need to be a registered user or login to post a comment

1,286,465 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:

Facebook ConnectGmail or other Google Account
Hotmail or Microsoft Windows LiveStackOverflow
GitHubYahoo


Comments:

1. Brilliant work - Jacob Fogg (2014-10-06 20:32)
Brilliant work... - 0 replies
Read the whole comment and replies


<< Previous: PHP 5.7 New Features ...

  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP Developer working...   Post a comment Post a comment   See comments See comments (1)   Trackbacks (0)