The father of PHP: PHP7 performance Double key Disclosure

Source: Internet
Author: User
Tags add end hhvm integer php and version variable drupal

20-year-old Web programming language PHP, the fastest in the end of October released PHP 7 new edition, this is the first major revision in ten years, the biggest feature is a big breakthrough in performance, can be compared to the previous version of PHP 5 faster than one, PHP's father Rasmus Lerdorf said, It can even be faster than the PHP program under the HHVM virtual machine.

HHVM is the face book for its own web site features tailored to the PHP optimization mechanism, does not necessarily apply to any site. But Rasmus Lerdorf says one of the new goals is to make any web developer, even when using the development framework Drupal, the Open-source e-business system OpenCart, have the ability to use HHVM technology without losing it. On the eve of the new release, he also took advantage of the PHPCONF Taiwan Annual meeting to share the key to a great breakthrough in PHP 7 performance.

A 20 years after a number of revisions and numerous optimization of the mature language, but also to improve the performance of one-fold breakthrough is not easy, Rasmus Lerdorf Frankly, unlike the general new projects are likely to find a lot of improvement space, the new version of PHP is not modified part of the program to achieve such results. On the contrary, through a lot of detail optimization and performance accumulation, PHP 7 has the ability to perform without HHVM.

Rasmus Lerdorf and the PHP core contribution team spent a lot of effort to reduce the number of bits of memory that were moved during the program's operation, thereby accelerating performance. For example, the data architecture for storing variables in PHP zval from 24 bits to 16 bits, Hashtable from 72 to 56 bits, and view the functions in PHP to think about any room for improved performance.

In addition to starting from the use of reduced memory, Rasmus Lerdorf examines the workings of the CPU's cache line, understands how program code interacts with the CPU, compiles program code in a new CPU architecture, and ensures that PHP 7 's program code conforms to the modern CPU architecture. Although the performance contribution of each project is less than 0.5% per cent, the overall revision of the integrated results can be made so much progress due to the number of optimized projects, or the repeated calls of an improved function by the application.

Motivated by HHVM, the decision to build PHP with both performance and functionality

Facebook created a virtual machine HHVM to optimize PHP operations with JIT compilation. While HHVM has fast execution performance, the design optimized for a specific purpose can only satisfy a small number of developers. Conversely, Rasmus Lerdorf want to improve PHP performance, but also want to meet the needs of high-end users and amateur users, so that PHP 70% for both performance and common features of the program language.

However, it is not difficult to develop a programming language that is suitable for a small number of people on the market, but the PHP project targets many objects and must be consistent with the needs of both amateur and professional developers, and development is difficult to reach because there is always a need for some groups to be met, "it's like a large spray of water pipes, And everyone's clothes will be wet a little, but no one's clothes are completely soaked. "rasmus Lerdorf analogy.

PHP without the use of the external framework of the performance of the operation is excellent, but by the impact of the framework, the original can be processed in a few seconds thousands of web page requirements of PHP, the performance of a substantial decline, to deal with only dozens of requirements. Rasmus Lerdorf said that before HHVM, users were more concerned about PHP's ability to reduce web page development than the performance requirements of PHP, which made it easier for developers to work. But after Facebook launched the HHVM, many users who value PHP performance have been drawn, making Rasmus Lerdorf aware of the performance requirements of many users. He began to think about how to merge HHVM's JIT architecture with PHP.

But Rasmus Lerdorf says that PHP and HHVM are quite different in architectural design, for example, the HHVM multithreaded architecture is not very solid. In addition, the portability of HHVM is still a long way from being able to operate on the Windows platform, and PHP has a lot of developers in the Windows environment, and HHVM can't take care of those users.

Rasmus Lerdorf says he can't give up PHP's main architecture, although they've considered merging both, but HHVM has a lot of restrictions on how to use it. While HHVM is a great tool for Facebook and many developers, the scope of HHVM is not broad enough for a PHP project to meet the needs of specific projects such as Facebook or Wikipedia.

Non-strong-type language of PHP, import JIT is difficult

However, it is very difficult to add JIT compilation to PHP. Rasmus Lerdorf says that the JIT must learn to identify the operating mode (Patterns) of the program, such as what parts are important program code, and when the program is called, or which parts of the program will call before the procedure is run.

Rasmus Lerdorf analogy, in many cars, the JIT must be able to predict which part of the car will turn right, which part of the car will turn left or some color car will go straight, "and the JIT must be fully predicted correctly, otherwise the performance will be greatly reduced." "However, if the forecast is correct, the performance of the program will improve significantly."

It is not easy to add JIT to the compilation of general programming languages, Rasmus Lerdorf said, because the dynamic properties of PHP make it difficult to add JIT. For example, the developer declares that the parameter $a value is 1, but does not mean that all the $ A values for the program are 1, because the parameter values in PHP can be easily redefined. In C, when a developer declares that argument A is an integer, then A is always an integer. If there is any place in the program declaring a to be a type other than integers, the compilation cannot be performed. And because C language is such a strong program language, "jit can predict variable A as an integer, but in PHP, we do not have this luxury. He explains that HHVM's approach is to assume that a is always an integer when the JIT learns that a is an integer type.

and HHVM in order to use JIT compilation, to a certain extent, limited the development of PHP. HHVM users must be aware of the nature of the variable, but using PHP developers, you can declare a class that is not of the nature, and then specify the variable attributes of the category later. "In the absence of any restrictions, the JIT into PHP is what we need to do." He said that PHP must take into account the WordPress, Drupal and other framework developers, can not arbitrarily stop the support of these frameworks. Therefore, compared with HHVM, PHP in the conditions of the JIT to create more restrictions.

But, "it doesn't mean we can't do JIT." In addition, we also want to control the development trend of PHP. "rasmus Lerdorf said.

Currently, one of PHP's core contributors, Dmitry Stogov, develops a prototype JIT and uses some experimental applications to test the operation. Rasmus Lerdorf says that if this JIT is used to perform certain repetitive operations or loop programs, it can make PHP 7 performance 10 times times faster.

But he also admits that when this experimental JIT is used for WordPress, there is no acceleration, "we want to build the JIT is not what to learn in college textbooks, but the real world to operate the JIT." "he said. Because PHP has always been such an ideal, trying to solve problems in people's lives, and can operate in the real world online environment, not just the existence of textbooks in the theory.

Rasmus Lerdorf said he spent at least 16 hours a day developing PHP when PHP was first published. But at present he has gradually reduced his investment in development and focused his efforts on promoting and lecturing around the world. "Instead of developing it yourself, it's better to motivate people who are smarter than me and willing to spend 18 hours a day writing programs to develop PHP," he quipped. He says his ultimate goal is that there is no line of code written by him in PHP, "any growing project should not be led by a developer, and the old code should be replaced by new code." "And he believes that other developers should target this."



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.