Author: Manuel Lemos
Viewers: 50
Last month viewers: 15
Categories: PHP Performance, News
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?
Recki-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.5 | Recki-CT | hhvm 3.2 | hippy-c | qb | |
---|---|---|---|---|---|
simple() | 139.63357 | 1.00000 | 8.30447 | 7.65693 | 8.35018 |
simplecall() | 38.99476 | FAIL | 1.32552 | 1.00000 | FAIL |
simpleucall() | 54.02041 | 1.00000 | 3.52439 | 1.51072 | 47.91090 |
simpleudcall() | 52.14534 | 1.00000 | 3.75936 | 1.41614 | 47.55259 |
mandel() | 21.26249 | 1.00000 | 2.03372 | 2.11208 | FAIL |
mandel_typed() | 23.16553 | 1.00000 | 2.11128 | 2.09212 | 3.00061 |
mandel2() | 24.43275 | 1.00000 | 2.57704 | 1.87802 | FAIL |
mandel2_typed() | 23.79989 | 1.00000 | 2.90105 | 1.57193 | 7.11054 |
ackermann(7) | 35.04870 | 1.00000 | 2.27557 | 103.45436 | 621.72526 |
ary(50000) | 1.39338 | FAIL | 1.00000 | 4.47888 | FAIL |
ary2(50000) | 1.26952 | FAIL | 1.00000 | 2.28231 | FAIL |
ary3(2000) | 5.96015 | FAIL | 1.70997 | 1.00000 | FAIL |
fibo(30) | 39.48440 | 1.00000 | 1.60647 | 16.40883 | FAIL |
hash1(50000) | 1.70014 | FAIL | 1.00000 | 3.27314 | FAIL |
hash2(500) | 2.23648 | FAIL | 1.00000 | 1.30044 | FAIL |
heapsort(20000) | 3.67800 | FAIL | 1.00000 | 4.96699 | FAIL |
matrix(20) | 4.38364 | FAIL | 1.00000 | 37.72782 | FAIL |
nestedloop(12) | 29.24924 | 1.00000 | 2.91459 | 3.07568 | FAIL |
sieve(30) | 10.95413 | FAIL | 1.00000 | 4.95152 | FAIL |
strcat(200000) | 1.48186 | FAIL | 2.06003 | 1.00000 | FAIL |
jumpapaluza(50, 50) | 11.67746 | 1.09240 | 1.48192 | 1.00000 | FAIL |
bitapaluza1(21) | 63.33357 | 1.00000 | 21.39655 | 1.46851 | FAIL |
bitapaluza2(18) | 21.83346 | 1.00000 | 6.19715 | 2.59416 | FAIL |
Future Developments
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
Login Immediately with your account on:
Comments:
1. Brilliant work - Jacob Fogg (2014-10-06 20:32)
Brilliant work... - 0 replies
Read the whole comment and replies