SlideShare una empresa de Scribd logo
1 de 20
PHP 5.4 Performance
                 Thanks to Dmitry Stogov

Laruence
@laruence
http://www.laruence.com/
PHP


  •   1995
  •   77.3%
  •   5.4
  •   4x
PHP Performance Evaluation

                               bench.php

 PHP 5.0                                                   13




 PHP 5.1                              6.5




 PHP 5.2                        5.6




 PHP 5.3                 3.9




 PHP 5.4           3.3


           0   2         4       6           8   10   12        14
                                       sec
PHP Performance Evaluation

                                  micro_bench.php

  PHP 5.0                                                           57.44




  PHP 5.1                                         31.86




  PHP 5.2                                 28.55




  PHP 5.3                         22.66




  PHP 5.4            12.67


            0   10           20           30              40   50    60     70
                                                   sec
New freatures


  •   Traits
  •   Built-in web server
  •   Array de-referencing
  •   Class member access on instantiation
  •   Shortened array syntax
  •   Binary number format
  •   …

  • 我们今天只讲5.3到5.4的优化
Delayed Hashtable Allocation


  •   很多的HashTable都是空的
  •   类的静态属性表, 常量表, 函数表
  •   用户定义的空数组
  •   推迟对HashTable的Buckets的内存分配, 直到第一个元素被插入
Literal Tables


   •   每一条VM指令, 都包含俩个操作数
   •   每一个操作数中, 都有一个constant成员, 这在大部分时候, 是没有用的.
   •   我们把所有的常量操作数, 都放在一个线性表里面,
   •   指令占用的内存数, 从76byte降低到了28byte(X86)
Literal Tables
Runtime Binding Cache


  •   减少符号查找次数
  •   基于Literal Table.
  •   一次查找, 就Cache起来
  •   多态带来了例外
Runtime Binding Cache
Internal String


   •   编译期已知的字符串
   •   对于多个Constant String, 只保存一份
   •   使用比较Char * pointer相等来代替strcmp
   •   避免了estrdup和efree
   •   预先计算Hash Value
Properties Directly Access


   • 查找一个属性, 需要至少2次HashTable 查找
   • 我们使用线性表, 来直接保存Properties
   • 减少一次HashTable查找
Properties Directly Access
Zend Signal


  •   PHP需要信号屏蔽来保证一些函数的安全
  •   信号屏蔽需要系统调用
  •   HANDLE_BLOCK/UNBLOCK_INTERRUPUTIONS需要SAPI自己实现
  •   为HashTable的API加入系统调用, 将会带来性能问题
Request Startup/Shutdown


  • 加速扩展的Request启停
  • 避免遍历整个扩展列表
  • 调用需要调用的
Ternary


  • 三元式每次都会复制要传递的值
  • 不支持Copy On Write机制
FastCGI SAPI Optimization


  • FastCGI再接受请求的时候, 因为大量的内存分配导致性能有问题
  • 我们改用了Stack Based的内存分配方式
  • FastCGI的Parameters Hashtable改用了更加快速的Hash 算法
More….


  •   Improved performance of @ (silence) operator
  •   ZEND_RETURN -> ZEND_RETURN, ZEND_RETURN_BY_REF
  •   ZEND_RECV result value is always IS_CV
  •   ZEND_CATCH has to be used with constant class name
  •   Remove break $var
Real-life Benchmarks
Q&A

Más contenido relacionado

La actualidad más candente

PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向Shengyou Fan
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由Shengyou Fan
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定Shengyou Fan
 
View 與 Blade 樣板引擎
View 與 Blade 樣板引擎View 與 Blade 樣板引擎
View 與 Blade 樣板引擎Shengyou Fan
 
專案啟動與環境設定
專案啟動與環境設定專案啟動與環境設定
專案啟動與環境設定Shengyou Fan
 
柴锋 跨平台移动应用的自动化验收测试
柴锋 跨平台移动应用的自动化验收测试柴锋 跨平台移动应用的自动化验收测试
柴锋 跨平台移动应用的自动化验收测试Trinea Trinea
 
開發環境建置
開發環境建置開發環境建置
開發環境建置Shengyou Fan
 
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹Shengyou Fan
 
Route 路由控制
Route 路由控制Route 路由控制
Route 路由控制Shengyou Fan
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者Shengyou Fan
 
成為全能 php 攻城獅
成為全能 php 攻城獅成為全能 php 攻城獅
成為全能 php 攻城獅Shengyou Fan
 
開發環境建置
開發環境建置開發環境建置
開發環境建置Shengyou Fan
 
Laravel - 系統全攻略
Laravel - 系統全攻略Laravel - 系統全攻略
Laravel - 系統全攻略Vincent Chi
 
Jaskell Core Parsec
Jaskell Core ParsecJaskell Core Parsec
Jaskell Core ParsecMarch Liu
 
選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅Shengyou Fan
 

La actualidad más candente (20)

PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向
 
課程簡介
課程簡介課程簡介
課程簡介
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定
 
View 與 Blade 樣板引擎
View 與 Blade 樣板引擎View 與 Blade 樣板引擎
View 與 Blade 樣板引擎
 
專案啟動與環境設定
專案啟動與環境設定專案啟動與環境設定
專案啟動與環境設定
 
柴锋 跨平台移动应用的自动化验收测试
柴锋 跨平台移动应用的自动化验收测试柴锋 跨平台移动应用的自动化验收测试
柴锋 跨平台移动应用的自动化验收测试
 
開發環境建置
開發環境建置開發環境建置
開發環境建置
 
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
 
Route 路由控制
Route 路由控制Route 路由控制
Route 路由控制
 
RSpec & TDD Tutorial
RSpec & TDD TutorialRSpec & TDD Tutorial
RSpec & TDD Tutorial
 
驗證與訊息
驗證與訊息驗證與訊息
驗證與訊息
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
 
成為全能 php 攻城獅
成為全能 php 攻城獅成為全能 php 攻城獅
成為全能 php 攻城獅
 
使用 Controller
使用 Controller使用 Controller
使用 Controller
 
開發環境建置
開發環境建置開發環境建置
開發環境建置
 
Laravel - 系統全攻略
Laravel - 系統全攻略Laravel - 系統全攻略
Laravel - 系統全攻略
 
驗證與訊息
驗證與訊息驗證與訊息
驗證與訊息
 
Jaskell Core Parsec
Jaskell Core ParsecJaskell Core Parsec
Jaskell Core Parsec
 
選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅
 

Destacado

The secret of PHP7's Performance
The secret of PHP7's Performance The secret of PHP7's Performance
The secret of PHP7's Performance Xinchen Hui
 
PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & PerformanceXinchen Hui
 
PHP7 - For Its Best Performance
PHP7 - For Its Best PerformancePHP7 - For Its Best Performance
PHP7 - For Its Best PerformanceXinchen Hui
 
China PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 pptChina PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 pptXinchen Hui
 
High Performance Solution for PHP7
High Performance Solution for PHP7High Performance Solution for PHP7
High Performance Solution for PHP7Xinchen Hui
 
A History of PHP
A History of PHPA History of PHP
A History of PHPXinchen Hui
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life CycleXinchen Hui
 

Destacado (8)

The secret of PHP7's Performance
The secret of PHP7's Performance The secret of PHP7's Performance
The secret of PHP7's Performance
 
PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & Performance
 
PHP7 - For Its Best Performance
PHP7 - For Its Best PerformancePHP7 - For Its Best Performance
PHP7 - For Its Best Performance
 
China PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 pptChina PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 ppt
 
Php performance
Php performancePhp performance
Php performance
 
High Performance Solution for PHP7
High Performance Solution for PHP7High Performance Solution for PHP7
High Performance Solution for PHP7
 
A History of PHP
A History of PHPA History of PHP
A History of PHP
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
 

Similar a Php 5.4 performance

Golang 高性能实战
Golang 高性能实战Golang 高性能实战
Golang 高性能实战rfyiamcool
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 
Internal php and gdb php core
Internal php and gdb php coreInternal php and gdb php core
Internal php and gdb php corealpha86
 
PHP Optimization for Millions Visits Level
PHP Optimization for Millions Visits LevelPHP Optimization for Millions Visits Level
PHP Optimization for Millions Visits LevelHo Kim
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發俊仁 陳
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
Web coding principle
Web coding principleWeb coding principle
Web coding principleZongYing Lyu
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合Qiangning Hong
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7Justin Lin
 
Spring mvc
Spring mvcSpring mvc
Spring mvcpepsixp
 
淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践丁 宇
 
Kafka cluster best practices
Kafka cluster best practicesKafka cluster best practices
Kafka cluster best practicesRico Chen
 
Phalcon phpconftw2012
Phalcon phpconftw2012Phalcon phpconftw2012
Phalcon phpconftw2012Rack Lin
 
Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯Hash Lin
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdfbj_qa
 
Hbase介绍
Hbase介绍Hbase介绍
Hbase介绍Kay Yan
 
Mysql调优
Mysql调优Mysql调优
Mysql调优ken shin
 

Similar a Php 5.4 performance (18)

Golang 高性能实战
Golang 高性能实战Golang 高性能实战
Golang 高性能实战
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Internal php and gdb php core
Internal php and gdb php coreInternal php and gdb php core
Internal php and gdb php core
 
PHP Optimization for Millions Visits Level
PHP Optimization for Millions Visits LevelPHP Optimization for Millions Visits Level
PHP Optimization for Millions Visits Level
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
HBase
HBaseHBase
HBase
 
Web coding principle
Web coding principleWeb coding principle
Web coding principle
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践
 
Kafka cluster best practices
Kafka cluster best practicesKafka cluster best practices
Kafka cluster best practices
 
Phalcon phpconftw2012
Phalcon phpconftw2012Phalcon phpconftw2012
Phalcon phpconftw2012
 
Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf
 
Hbase介绍
Hbase介绍Hbase介绍
Hbase介绍
 
Mysql调优
Mysql调优Mysql调优
Mysql调优
 

Php 5.4 performance

  • 1. PHP 5.4 Performance Thanks to Dmitry Stogov Laruence @laruence http://www.laruence.com/
  • 2. PHP • 1995 • 77.3% • 5.4 • 4x
  • 3. PHP Performance Evaluation bench.php PHP 5.0 13 PHP 5.1 6.5 PHP 5.2 5.6 PHP 5.3 3.9 PHP 5.4 3.3 0 2 4 6 8 10 12 14 sec
  • 4. PHP Performance Evaluation micro_bench.php PHP 5.0 57.44 PHP 5.1 31.86 PHP 5.2 28.55 PHP 5.3 22.66 PHP 5.4 12.67 0 10 20 30 40 50 60 70 sec
  • 5. New freatures • Traits • Built-in web server • Array de-referencing • Class member access on instantiation • Shortened array syntax • Binary number format • … • 我们今天只讲5.3到5.4的优化
  • 6. Delayed Hashtable Allocation • 很多的HashTable都是空的 • 类的静态属性表, 常量表, 函数表 • 用户定义的空数组 • 推迟对HashTable的Buckets的内存分配, 直到第一个元素被插入
  • 7. Literal Tables • 每一条VM指令, 都包含俩个操作数 • 每一个操作数中, 都有一个constant成员, 这在大部分时候, 是没有用的. • 我们把所有的常量操作数, 都放在一个线性表里面, • 指令占用的内存数, 从76byte降低到了28byte(X86)
  • 9. Runtime Binding Cache • 减少符号查找次数 • 基于Literal Table. • 一次查找, 就Cache起来 • 多态带来了例外
  • 11. Internal String • 编译期已知的字符串 • 对于多个Constant String, 只保存一份 • 使用比较Char * pointer相等来代替strcmp • 避免了estrdup和efree • 预先计算Hash Value
  • 12. Properties Directly Access • 查找一个属性, 需要至少2次HashTable 查找 • 我们使用线性表, 来直接保存Properties • 减少一次HashTable查找
  • 14. Zend Signal • PHP需要信号屏蔽来保证一些函数的安全 • 信号屏蔽需要系统调用 • HANDLE_BLOCK/UNBLOCK_INTERRUPUTIONS需要SAPI自己实现 • 为HashTable的API加入系统调用, 将会带来性能问题
  • 15. Request Startup/Shutdown • 加速扩展的Request启停 • 避免遍历整个扩展列表 • 调用需要调用的
  • 16. Ternary • 三元式每次都会复制要传递的值 • 不支持Copy On Write机制
  • 17. FastCGI SAPI Optimization • FastCGI再接受请求的时候, 因为大量的内存分配导致性能有问题 • 我们改用了Stack Based的内存分配方式 • FastCGI的Parameters Hashtable改用了更加快速的Hash 算法
  • 18. More…. • Improved performance of @ (silence) operator • ZEND_RETURN -> ZEND_RETURN, ZEND_RETURN_BY_REF • ZEND_RECV result value is always IS_CV • ZEND_CATCH has to be used with constant class name • Remove break $var
  • 20. Q&A