- Mastering The Faster Web with PHP,MySQL,and JavaScript
- Andrew Caya
- 330字
- 2021-06-25 21:16:58
PHP 7 optimizations
PHP 7 is in itself a major optimization. A good part of PHP's code base was rewritten for this release and most official benchmarks show that, generally speaking, almost any PHP code will run about two times faster or more with PHP 7 than with previous versions.
PHP is programmed in C and optimizing the performance of Zend's Ahead-Of-Time (AOT) compiler depends ultimately on using the C compiler's internal logic in an optimized way. This latest version of PHP is the result of many years of research and experiments by Zend. The greater part of these optimizations was implemented by eliminating the performance overhead generated by certain PHP internal structural constructs and data structures. According to Dmitry Stogov[1], a typical real-life PHP application spends about 20% of the CPU time in the memory manager, 10% doing hash table operations, 30% in internal functions and only 30% in the VM. In order to optimize the execution of PHP code, PHP 7's new version of the Zend Engine had to start by representing source code in an Abstract Syntax Tree (AST), thus allowing the engine to generate better quality Intermediate Representations (IR) of the source code and, since PHP 7.1, to be able to remove dead code and reduce as many expressions as possible to their static representation through Static Single Assignment (SSA) form and type inference. In turn, this allows the engine to only allocate necessary data structures to the stack instead of the heap in memory at runtime.
This is very important in order to understand the rest of this chapter, as it allows us to see why datatype juggling and dynamic structures in general will create most of the overhead by bloating memory allocation at runtime, why certain data structures had to be re-implemented to allow for C-level performance and why immutability is a developer's ally when trying to achieve better code performance. Let's have a look at these elements more closely.
- 高手是如何做產(chǎn)品設(shè)計(jì)的(全2冊(cè))
- Fundamentals of Linux
- Drupal 8 Blueprints
- 深入淺出WPF
- Python深度學(xué)習(xí)
- Internet of Things with the Arduino Yún
- Learning Network Forensics
- 大模型RAG實(shí)戰(zhàn):RAG原理、應(yīng)用與系統(tǒng)構(gòu)建
- Spring Boot Cookbook
- 快人一步:系統(tǒng)性能提高之道
- 領(lǐng)域驅(qū)動(dòng)設(shè)計(jì):軟件核心復(fù)雜性應(yīng)對(duì)之道(修訂版)
- 區(qū)塊鏈技術(shù)進(jìn)階與實(shí)戰(zhàn)(第2版)
- Arduino計(jì)算機(jī)視覺編程
- 自學(xué)Python:編程基礎(chǔ)、科學(xué)計(jì)算及數(shù)據(jù)分析(第2版)
- 工業(yè)機(jī)器人離線編程