search
HomeBackend DevelopmentPHP TutorialThe Father of PHP: The key to doubling the performance of PHP7 is revealed_PHP Tutorial

Father of PHP: Revealing the key to doubling the performance of PHP7

The 20-year-old veteran web programming language PHP will release a new version of PHP 7 as soon as the end of October. This is the first major revision in ten years. The biggest feature is a major breakthrough in performance, which is better than the previous version. PHP 5 is twice as fast. Rasmus Lerdorf, the father of PHP, said that it can even perform faster than the PHP program under the HHVM virtual machine.

HHVM is a PHP optimization mechanism customized by Facebook for the characteristics of its own website, and may not be applicable to any website. But Rasmus Lerdorf said that one of the goals of the new version is to enable any website developer, even when using the development framework Drupal and the open source e-commerce system Opencart, to have the same performance as using HHVM technology. On the eve of the release of the new version, he also took the opportunity to come to Taiwan to attend the PHPConf Taiwan annual conference to share the key to the performance breakthrough of PHP 7.

For a mature language that has gone through many revisions and countless optimizations in the past 20 years, it is not easy to have a breakthrough that doubles the performance. Rasmus Lerdorf said frankly that unlike ordinary new projects, it is often easy to find a lot of room for improvement. The new version of PHP does not achieve such results by modifying some programs. On the contrary, after a lot of detailed optimization and performance accumulation, PHP 7 has an execution performance that is not inferior to HHVM.

Rasmus Lerdorf and the PHP core contribution team have spent a lot of effort to reduce the number of memory bits moved when the program is running, thereby speeding up execution performance. For example, the data structure zval for storing variables in PHP is reduced from 24 bits to 16 bits, and Hashtable is reduced from 72 bits to 56 bits. The functions in PHP are reviewed to consider whether there is any room for improvement in performance.

In addition to reducing memory usage, Rasmus Lerdorf also examined the operating principle of the CPU's Cache line to understand how the program code interacts with the CPU, how the compiler compiles the program code under the new CPU architecture, and other details to ensure that PHP 7 The program code conforms to the architecture of modern CPUs. Although the optimization of each project contributes less than 0.5% to performance, because there are many optimization projects, or a certain improved function is repeatedly called by the application, the overall effect of the correction can make such a big progress.

Inspired by HHVM, we decided to build PHP with both performance and functionality

In order to optimize the operation of PHP, Facebook created a virtual machine HHVM with JIT compilation. Although HHVM has fast execution performance, its design optimized for specific purposes can only satisfy a small number of developers. On the contrary, in addition to improving the performance of PHP, Rasmus Lerdorf also wants to meet the needs of high-end users and amateur users at the same time, making PHP 7 a programming language with both performance and general functions.

However, it is not difficult to develop a programming language that meets the needs of a small number of people in the market. However, the PHP project aims at many targets and must meet the needs of amateur users and professional developers at the same time. Development is difficult to cover everything because there will always be The needs of some groups cannot be met. "It's like spraying a large area with a water pipe. Everyone's clothes will get a little wet, but no one's clothes will be completely soaked." Rasmus Lerdorf said.

The computing performance of PHP without the use of external frameworks is very good. However, due to the influence of external frameworks, PHP, which could originally process thousands of web page requests in a few seconds, has a significant performance drop and can only process dozens of web pages. Require. Rasmus Lerdorf said that before the emergence of HHVM, users were more concerned about whether PHP could reduce the difficulty of web development than the performance requirements of PHP, and these frameworks can make developers' work easier. However, after Facebook launched HHVM, it attracted many users who valued PHP performance, making Rasmus Lerdorf realize that many users have performance needs. He began to think about how to integrate HHVM's JIT architecture with PHP.

But Rasmus Lerdorf said that PHP and HHVM are quite different in architectural design. For example, HHVM's multi-threaded architecture is not very stable. In addition, the portability of HHVM is not good, and it is still a long way from being able to run on the Windows platform. PHP has many developers developing in the Windows environment, and HHVM cannot take care of those users.

Rasmus Lerdorf said that he could not give up the main architecture of PHP. Although they had considered integrating the two, HHVM had many limitations in its use. Although HHVM is a very good tool for Facebook and many developers, for PHP projects, the scope of use of HHVM is not broad enough and can only meet the needs of specific projects such as Facebook or Wikipedia.

PHP, which is not a strongly typed language, is even more difficult to import JIT

However, adding JIT compilation to PHP is very difficult. Rasmus Lerdorf said that JIT must learn to identify the operating patterns of the program, such as understanding which parts are important program codes, and predicting when the program will be called or which parts of the program will be called before the program is run.

Rasmus Lerdorf said that in many cars, JIT must be able to predict which part of the car will turn right, which part of the car will turn left, or which cars of certain colors will go straight. "And JIT must predict all of them correctly, otherwise Performance will be greatly reduced. "However, if the prediction is correct, program execution performance will be greatly improved.

It is not easy to add JIT to the compilation of general programming languages. Rasmus Lerdorf said that it is even more difficult to add JIT due to the dynamic attribute of PHP (dynamic). For example, he said that the developer declared the value of parameter $a to be 1, but it does not mean that the value of all $a in the program is 1, because the parameter value can be easily redefined in PHP. In C language, when the developer declares parameter a to be an integer, then a will always be an integer. If anywhere in the program declares that a is a type other than integer, even compilation will not be possible. And because C language is a strongly typed programming language, "JIT can predict that variable a is an integer, but in PHP, we don't have this luxury." He explained that HHVM's approach is that when JIT learns that a is an integer type After that, it is assumed that a is always an integer.

In order to use JIT compilation, HHVM has restricted the development of PHP to some extent. Users of HHVM must clearly declare the nature of variables, but developers using PHP can first declare a category without attributes (Class), and then specify the variable attributes of the category. "Without any restrictions, adding JIT to PHP is what we have to do." He said that PHP must take into account the developers of WordPress, Drupal and other frameworks, and cannot arbitrarily stop supporting these frameworks. Therefore, compared with HHVM, PHP has more restrictions on creating JIT.

However, "This does not mean that we cannot do JIT. In addition, we must also control the development direction of PHP." Rasmus Lerdorf said.

Currently, Dmitry Stogov, one of the core contributors to PHP, is developing a prototype JIT and using some experimental applications to test operation. Rasmus Lerdorf said that if this JIT is used to perform certain repetitive operations or loop programs, the performance of PHP 7 can be made 10 times faster.

However, he also admitted that when this experimental JIT was used in WordPress, it did not achieve any acceleration effect. "The JIT we want to create is not something learned in college textbooks, but something that can be used in the real world." Operational JIT," he said. Because PHP has always held such ideals, trying to solve problems in people's lives and operating in real-world online environments, not just theories in textbooks.

Rasmus Lerdorf said that when PHP first came out, he spent at least 16 hours a day developing PHP. But now he has gradually reduced his investment in development and instead devoted his energy to publicity and speeches around the world. He jokingly said: "Instead of developing it myself, it is better to inspire people who are far smarter than me and willing to spend eighteen hours a day to write programs to develop PHP." He said that his ultimate goal is that there is not a single line in PHP written by him. Programming code, "Any growing project should not be led by one developer. Old program code should be replaced with new program code." And he believes that other developers should aim for this.



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1065279.htmlTechArticleFather of PHP: The key to doubling the performance of PHP7 is revealed. The 20-year-old old web programming language PHP will be launched in 10 at the earliest A new version of PHP 7 will be released at the end of the month. This is the first major revision in ten years. The biggest feature is its performance...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何优化Java开发中的文件压缩解压性能如何优化Java开发中的文件压缩解压性能Jul 01, 2023 am 11:54 AM

如何优化Java开发中的文件压缩解压性能随着互联网技术的不断发展,文件传输和存储成为我们日常开发中经常遇到的需求。为了减小网络传输的带宽消耗和文件存储的空间占用,我们通常需要对文件进行压缩。在Java开发中,常用的文件压缩格式有ZIP和GZIP。本文将介绍如何优化Java开发中的文件压缩解压性能,帮助提高效率。一、合理选择压缩算法在Java开发中,进行文件压

电脑性能看哪些方面电脑性能看哪些方面Dec 23, 2020 pm 01:54 PM

电脑性能看如下几个方面:1、电脑安装的操作系统的版本;2、电脑所配置的处理器类型;3、电脑安装的内存大小;4、操作系统是32位的还是64位的。

Vue3中的lazy函数详解:懒加载组件提高应用性能Vue3中的lazy函数详解:懒加载组件提高应用性能Jun 19, 2023 am 08:39 AM

Vue3是一款流行的JavaScript框架,它具有易学易用、高效稳定的特点,尤其擅长构建单页应用程序(SPA)。Vue3中的lazy函数,作为懒加载组件的利器之一,可以很大程度上提高应用程序的性能。本文将详解Vue3中的lazy函数的使用方法与原理,以及它在实际开发中的应用场景和优点。什么是懒加载?在传统的前后端分离的开发中,前端开发人员往往需要处理大量的

Java开发中如何优化字符串查找性能Java开发中如何优化字符串查找性能Jun 29, 2023 am 11:12 AM

在Java开发中,字符串查找是一个常见且关键的操作。无论是在文本处理、数据分析还是系统日志分析等应用场景中,字符串的查找性能都对程序的整体性能有着重要影响。因此,如何优化字符串查找性能成为了Java开发中不可忽视的问题。一、使用indexOf()方法代替contains()方法在字符串查找中,Java提供了两个常用的方法:indexOf()和contains

Java随机数生成性能优化方法Java随机数生成性能优化方法Jun 30, 2023 pm 12:25 PM

如何优化Java开发中的随机数生成性能随机数在计算机科学中有广泛的应用,特别是在密码学、模拟、游戏等领域。在Java开发中,我们常常需要生成随机数来满足各种需求。然而,随机数生成的性能通常是开发者关注的问题之一。本文将探讨如何优化Java开发中的随机数生成性能。使用ThreadLocalRandom类在Java7中引入了ThreadLocalRandom类

如何通过设置MySQL缓存来提高性能如何通过设置MySQL缓存来提高性能May 11, 2023 am 08:09 AM

MySQL是一种常用的关系型数据库管理系统(RDBMS),在各种应用场景下都得到广泛的应用。然而,在高并发、大数据量的情况下,MySQL数据库的性能受到挑战,特别是在读写操作频繁的场景下,容易出现性能瓶颈。为了提高MySQL数据库的性能,可以通过设置MySQL缓存来减少数据库的IO操作,从而提高MySQL的查询效率。在本文中,我们将介绍如何通过设置MySQL

自动驾驶决策规划技术详解自动驾驶决策规划技术详解Apr 04, 2023 pm 02:35 PM

随着深度强化学习技术的快速发展,越来越多的研究团队开始将其应用于自动驾驶决策规划中,将行为决策与运动规划模块相融合,直接学习得到行驶轨迹。 自动驾驶中的决策规划模块是衡量和评价自动驾驶能力最核心的指标之一,它的主要任务是在接收到传感器的各种感知信息之后,对当前环境作出分析,然后对底层控制模块下达指令。典型的决策规划模块可以分为三个层次:全局路径规划、行为决策、运动规划。01 引言在一套完整的自动驾驶系统中,如果将感知模块比作人的眼睛和耳朵,那么决策规划就是自动驾驶的大脑。大脑在接收到传感器的各种

一篇学会本地知识库对LLM的性能优化一篇学会本地知识库对LLM的性能优化Jun 12, 2023 am 09:23 AM

昨天一个跑了220个小时的微调训练完成了,主要任务是想在CHATGLM-6B上微调出一个能够较为精确的诊断数据库错误信息的对话模型来。不过这个等了将近十天的训练最后的结果令人失望,比起我之前做的一个样本覆盖更小的训练来,差的还是挺大的。这样的结果还是有点令人失望的,这个模型基本上是没有实用价值的。看样子需要重新调整参数与训练集,再做一次训练。大语言模型的训练是一场军备竞赛,没有好的装备是玩不起来的。看样子我们也必须要升级一下实验室的装备了,否则没有几个十天可以浪费。从最近的几次失败的微调训练来看

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.