For people who know me, it’s no secret that improving PHP performance is my main responsibility and passion in Zend. In general, since PHP 5.0 we have already speeded up PHP six times in synthetic tests and about twice in real projects. We did not stop improving the core of PHP and OPCache. But still, with the release of PHP 5.5, we didn’t manage to go much further and, together with the rest, we started experimenting with memory managers, JIT technology and other potential solutions.
I spent a lot of time experimenting with JIT, and even made a prototype of a transparent, LLVM-based, JIT compiler built into OPCache. The results for bench.php were amazing (0.219 seconds versus 2.175 - a tenfold increase for PHP 5.5), but for real projects we got only a couple percent of the performance increase. This made us look deeper into the characteristics of the executable environment and what was really a bottleneck. It is clear that the virtual machine was already well optimized, but it worked with data structures that constantly require allocation and freeing of memory and counting references to values. A typical real PHP application spends approximately 20% of CPU time in the memory manager, 10% in operations with hash tables, 30% in the built-in PHP functions, and only 30% in the virtual machine. Of course, we tried JIT only for the virtual machine code and in most cases this code still did the same memory operations. Therefore, we decided to change the focus and work on this large bottleneck. The idea was to change the data types to optimize the allocation of pieces of memory. This was a very difficult decision, since we needed to start a huge refactoring and we had no idea whether it would affect anything at all.
I am pleased to present to you the result of our work over the past four months. This is a PHP core refactoring, which significantly improves performance and memory usage, and most importantly provides the foundation for major improvements in the future, including JIT. I will miss the technical details (details are published here wiki.php.net/phpng ), but if in two words, then we changed the foundation by trying to keep most of the building unchanged. Already, the new core gives a 10-30% increase in performance, not only in tests, but also in real projects!
')
Some performance tests:
Wordpress 3.6 - 20.0% increase (253 vs 211 req / sec)
Drupal 6.1 - 11.7% increase (1770 vs 1585 req / sec
Qdig - 15.3% increase (555 vs 482 req / sec)
ZF test app - 30.5% increase (217 vs 166 req / sec)
On some applications, we got results even better than other PHP implementations.
It would be great if other people check their applications and compare them with their current version of PHP.
Refactoring is far from complete, as the emphasis was on checking whether there will be any positive result at all. Not all extensions are supported yet, some tests fail, and we also have a lot of ideas for future improvements.
But as it seems to us, we are confident enough to open it for Rivieu, feedback and community support. ... There is still a lot to be done to support all the PHP extensions and to continue to further improve the kernel.
Try refactored PHP and give your feedback on performance, memory usage and any problems.
The * phpng * branch can be found on php.net . There are also some instructions here wiki.php.net/phpng . ...
I would like to separately thank Xinchen and Nikita for a significant part of the work done!
I hope that this new kernel can make the new version of PHP, about which we talk so much, much more interesting.
Thanks to all!
Source: https://habr.com/ru/post/222219/
All Articles