SlideShare a Scribd company logo
1 of 51
Download to read offline
PHP 7
- New Engine For The Good Old Train
@laruence
About Me
•  Author of Yaf, Yar, Yac, Taint, Lua, etc
•  Maintainer of APC, Zend Opcache, Msgpack, etc
•  Chief software architect At Weibo since 2012
•  PHP core developer since 2011
•  Zend consultant since 2013
•  Core author of PHP7
About PHP
•  20 years history
•  Most popular Web service program language
•  Over 82% sites are use PHP as server program language
PHP 7 New Features
PHP 7?
•  PHP NG – Engine Refactor - performance improvements
•  Abstarct Syntanx Tree
•  Int64 Improvement
•  Uniform variable syntax
•  Native TLS
•  Consistently foreach behaviors
•  New <=>, **, ?? operaters
•  Return Type Declarations
•  Scalar Type Declarations
•  Exceptions in Engine
•  And Dozens features…
Abstract Syntax Tree
PHP	
 Parser	
 AST	
 Opcodes	
 Execution	
PHP	
 Parser	
 Opcodes	
 Execution	
•  PHP5
•  PHP7
Int64 Improvement
•  >2GB string
•  >2GB file uploading
•  Fully 64bits intgers cross platforms
Uniform Variables Syntanx
•  $foo()['bar']()
•  $foo['bar']::$baz
•  foo()() – (foo())()
•  $foo->bar()::baz()
•  (function() { ... })()
•  $this->{$name}()
•  [$obj, 'method']()
•  Foo::$bar['baz']()
PHP5: Foo::{$bar['baz']}()
PHP7: (Foo::$bar)['baz']()
Return Type Declarations
•  function foo(): array {
return [];
}
•  interface A {
static function make(): A;
}
•  function foo(): DateTime {
return null;
}
PHP Fatal error: Return value of foo() must be an instance of DateTime, null returned
Scalar Type Declarations
•  function foo(int num)
•  function bar (string name)
•  function foobar() : float {}
•  function add(int l, int r) : int {}
•  class A {
public function start (bool start) {}
}
Exceptions in Engine
•  Use of exceptions in Engine
try {
non_exists_func();
} catch (EngineException $e) {
echo "Exception: {$e->getMessage()}n";
}
 
Exception: Call to undefined function non_exists_func()
•  Uncaught Exception result to FATAL ERROR
non_exists_func();
PHP Fatal error: Call to undefined function non_exists()
PHP NG (Next Generation)
PHP Performance Evaluation
2.991
3.045
3.102
3.762
5.318
6.527
13.424
0 2 4 6 8 10 12 14 16
PHP-5.6
PHP-5.5
PHP-5.4
PHP-5.3
PHP-5.2
PHP-5.1
PHP-5.0
bench.php(sec)
PHP Performance Evaluation
112
110
107
82
75
0
0
0 20 40 60 80 100 120
PHP-5.6
PHP-5.5
PHP-5.4
PHP-5.3
PHP-5.2
PHP-5.1
PHP-5.0
Wordpress 3.6 home page qps
PHP Performance Evaluation
•  ~5 times faster from 5.0 to 5.6 in bench
•  ~2 times faster from 5.0 to 5.6 in real-life apps
•  No big performance improvement after 5.4
•  Zend VM is already highly optimized
•  Generate optimized codes based on run-time types inference
PHP Just In Time Compiler?
PHP	
 Parser	
 Opcodes	
TypeInf	
 JIT	
 Bytecodes
Execution
PHP Just In Time Compiler?
•  We created a POC of JIT compiler based on LLVM for PHP-5.5 in 2013
•  ~8 times speedup on bench.php
•  Negligible speedup on real-life apps (1% on Wordpress)
•  https://github.com/zendtech/php-src/tree/zend-jit
Wordpress profile
•  21% CPU time in meory manager
•  12% CPU time in hash tables operations
•  30% CPU time in internal functions
•  25% CPU time in VM
Wordpress profile
New Generation
•  It’s a refactoring
•  Main goal — achieve new performance level and make base for future
improvements
•  No new features for users (only internals)
•  Keep 100% compatibility in PHP behavior
•  May 2014 we opened the project
ZVAL
•  Zval is changed
ZVAL
•  No refcount for scalar types
•  zvals are always pre-allcocated or allocated in stack(nomore
MAKE_STD_ZVAL and ALLOC_ZVAL)
•  String using refcout instead of copy (zend_string)
•  gc_info, temporary_variables, should_free_var, cache_slot all in zval
•  New types: IS_TRUE, IS_FALSE, IS_REFERENCE, IS_INDIRECT
Zend VM
execute data
Internal Functions
zval zval zval zval zval
Uesr land
zend array
zval zval zval zval zval
stack zvals
zval zval zval zval zval
•  IS_UNDEF
•  IS_NULL
•  IS_FALSE
•  IS_TRUE
•  IS_LONG
•  IS_DOUBLE
•  IS_STRING
•  IS_ARRAY
•  IS_OBJECT
•  IS_RESOURCE
•  IS_REFERENCE
ZVAL
v28u4
tAp4 u2f826s
0 8 32 63
IS_S.RING/IS_ARRA0/IS_OBJEC./IS_RESRO/CE/...
r4f3ount 63_infotAp4
0 32 63
f826s
48
•  IS_NULL
•  IS_FALSE
•  IS_TRUE
•  IS_LONG
•  IS_DOUBLE
ZVAL NON REFCOUNED
value
type u2flags
0 8 32 63
•  IS_STRING
•  IS_ARRAY
•  IS_OBJECT
•  IS_RESOURCE
•  IS_REFERENCE
ZVAL REFCOUNED
IS_S.RING/IS_ARRA0/IS_OBJEC./IS_RESRO/CE/...
r4f3ount 63_infotyp4
0 32 63
f826s
48
•  New Internal Type: Zend String
IS_STRING
•  IS_STRING_PERSISTENT
•  IS_STR_INTERNED
•  IS_STR_PERMANENT
•  IS_STR_CONSTANT
un3igned l0ng ha3h_6alue
2efc0un4 gc_inf04y1e
0 32 63
flag3
48
3i8e_4 342ing_len
cha2[  ] 6al
•  New Internal Type: Zend Array
IS_ARRAY
•  IS_ARRAY_IMMUTABLE
refcount gc_infotype
0 32 63
flags
48
nTableMasku
Bucket *arData
nNumUsed nNumOfElements
.....
IS_OBJECT
•  Zend Object
•  IS_OBJ_APPLY_COUNT
•  IS_OBJ_DESTRUCTOR_CALLED
•  IS_OBJ_FREE_CALLED
zend_class_entry *ce
refcount gc_infotype
0 32 63
flags
48
zend_object_handlers *handlers
zend_array *properties
zend_array *guarders
zval *properties_table[1]
•  New Internal Type: Zend Reference
•  Reference is type
IS_REFERENCE
refco0nt gc_infot2pe
0 3   63
flags
48
3val val0e
HashTable – PHP 5
HashTable
nTableMasknTableSize
0 8 32 63
pInternalPointer
nNumOfElem
nNextFreeElement
Bucket *
pListHead
pListTail
arBuckets
pDestructor
Bucket *
Bucket *
.......
Bucket
hashval
nKeyLength
pDataPtr
pData
pListNext
pListPrev
pNext
pLast
arKey
Bucket
hashval
nKeyLength
pDataPtr
pData
pListNext
pListPrev
pNext
pLast
arKey
Zval
value
type
Zend Array – PHP 7
zend_array
refcounted
0 8 32 63
u
arData
idx
idx
Bucket 0
nTableMask
nNumUsed nNumOfElem
nTableSize InternalPointer
pNextFreeElement
pDestructor
.......
hashval
key
zval
Bucket 1
hashval
key
zval
Bucket 2 ......
Zend Array(HashTable)
•  Values of arrays are zval by default
•  HashTable size reduced from 72 to 56 bytes
•  Bucket size reduced from 72 to 32 bytes
•  Memory for all Buckets is allocated at once
•  Bucket.key now is a pointer to zend_string
•  Values of array elements are embedded into the Buckets
•  Improved data locality => less CPU cache misses
Function calling convention – PHP5
•  function add ($a, $b) {
return $a + $b;
}
add(1, 2);
send_val 1
send_val 2
do_fcall add (2)
1
2
call frame(add)
opcodes(main):
call frame(main)
recv 1 $a
recv 2 $b
zend_add $a, $b ~0
opcodes(add):
zend_return ~0
1
2
3
vm stack
Function calling convention – PHP7
•  function add ($a, $b) {
return $a + $b;
}
add(1, 2);
send_val 1
send_val 2
do_fcall 2
call frame(add)
init_fcall add
call frame(main)
recv 1 $a
recv 2 $b
zend_add $a, $b ~0
opcodes(add):
zend_return ~0
1
2
3
vm stack
Fast Parameters Parsing APIs
•  ~5% of the CPU time is spent in zend_parse_parameters()
•  For some simple functions the overhead of zend_parse_parameters() is
over 90%
Inline Frequently used simple functions
•  call_user_function(_array) => ZEND_INIT_USER_CALL
•  is_int/string/array/* etc => ZEND_TYPE_CHECK
•  strlen => ZEND_STRLEN
•  defined => ZEND+DEFINED
•  …
Faster zend_qsort
•  Refactor zend_qsort for better performance
•  Hybrid Sorting Algo(Quick Sort and Selection Sort)
•  <16 elements do stable sorting
•  $array = array(0 => 0, 1=>0); asort($array);
•  PHP5: array(1=>0, 0=>0);
•  PHP7: array(0=>1, 1=>0);
New Memory Manager
•  Friendly to moder CPU cache
•  less CPU cache misses
•  Faster builtin types allocating
•  ~5% CPU time reduce in wordpress homepage
Dozens of other improvements
•  Fast HashTable iteration APIs
•  Immutable array
•  Array duplication optimization
•  PCRE with JIT
•  BIND_GLOBAL instead of FETCH and ASSIGN_REF
•  More specifical DO_UCALL and DO_ICALL
•  Global registers for execute_data and opline(GCC-4.8+)
•  ZEND_ROPE_* for faster string concating
•  ZEND_CALL_TRAMPOLINE for faster__call/__callstatic
•  Dozens logic optimizations
•  ….
Wordpress profile (2015-04-14)
Wordpress profiled (2015-04-14)
•  >50% CPU IRs reduced
•  5% CPU time in meory manager
•  12% CPU time in hash tables operations
PHP7 Performance – Benchmark (2014-04-14)
1.186
2.991
3.045
3.102
3.762
5.318
6.527
13.424
0 2 4 6 8 10 12 14 16
PHP-7
PHP-5.6
PHP-5.5
PHP-5.4
PHP-5.3
PHP-5.2
PHP-5.1
PHP-5.0
bench.php(sec)
PHP7 Performance – Reallife App (2015-04-14)
311
112
110
107
82
75
0
0
0 50 100 150 200 250 300 350
PHP-7
PHP-5.6
PHP-5.5
PHP-5.4
PHP-5.3
PHP-5.2
PHP-5.1
PHP-5.0
wordpress 3.0.1 home page qps
PHP7 Performance (By Rasmus 2015-04-21)
PHP7 Performance (2015-04-21)
PHP7 Performance (2015-04-21)
PHP7 Performance (2015-03-15)
Always Do Your Own Benchmark
PHP 7 Next
•  Keep 99.99% compatible with PHP5
•  Keep Improving performance
•  Port common used PECL extensions (memcached, redis etc)
•  Release PHP 7 (oct 2015)
•  Restart JIT (Sep 2014)
Links
•  phpng:_Refactored_PHP_Engine_with_Big_Performance_Improveme
nt: http://news.php.net/php.internals/73888
•  PHPNG RFC: https://wiki.php.net/phpng
•  PHPNG Implementation details: https://wiki.php.net/phpng-int
•  Upgrading PHP extensions from PHP5 to PHPNG:
https://wiki.php.net/phpng-upgrading
•  Zeev <Benchmarking PHPNG>:
http://zsuraski.blogspot.co.il/2014/07/benchmarking-phpng.html
•  Rasmus <SPEEDING UP THE WEB WITH PHP 7>:
http://talks.php.net/fluent15#/
Questions?
Thanks

More Related Content

What's hot

Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architectureElizabeth Smith
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2LiviaLiaoFontech
 
PSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressiveMilad Arabi
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshopAdam Culp
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and coPierre Joye
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tigerElizabeth Smith
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Tim Bunce
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Muhamad Al Imran
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7Damien Seguy
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPANdaoswald
 
PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated FeaturesMark Niebergall
 

What's hot (20)

Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 
PSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend Expressive
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Stacking Up Middleware
Stacking Up MiddlewareStacking Up Middleware
Stacking Up Middleware
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated Features
 

Viewers also liked

PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & PerformanceXinchen Hui
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由Shengyou Fan
 
PHP 應用之一 socket funion : 偽 WEB Server
PHP 應用之一 socket funion : 偽 WEB ServerPHP 應用之一 socket funion : 偽 WEB Server
PHP 應用之一 socket funion : 偽 WEB Server志賢 黃
 
關聯式資料庫系統的規劃
關聯式資料庫系統的規劃關聯式資料庫系統的規劃
關聯式資料庫系統的規劃Simon Huang
 
微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)Xinchen Hui
 
JSON-lD
JSON-lDJSON-lD
JSON-lDCQD
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorialPTutorial Web
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvementsXinchen Hui
 
HTML CSS JavaScript 行動應用程式解決方案
HTML CSS JavaScript 行動應用程式解決方案HTML CSS JavaScript 行動應用程式解決方案
HTML CSS JavaScript 行動應用程式解決方案Ian Chen
 
PHP7 - For Its Best Performance
PHP7 - For Its Best PerformancePHP7 - For Its Best Performance
PHP7 - For Its Best PerformanceXinchen Hui
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?Nikita Popov
 
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...Badoo Development
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向Shengyou Fan
 
Weaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryWeaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryAlexander Lisachenko
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorialalexjones89
 

Viewers also liked (20)

PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & Performance
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由
 
errors in php 7
errors in php 7errors in php 7
errors in php 7
 
PHP 應用之一 socket funion : 偽 WEB Server
PHP 應用之一 socket funion : 偽 WEB ServerPHP 應用之一 socket funion : 偽 WEB Server
PHP 應用之一 socket funion : 偽 WEB Server
 
關聯式資料庫系統的規劃
關聯式資料庫系統的規劃關聯式資料庫系統的規劃
關聯式資料庫系統的規劃
 
微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)
 
JSON-lD
JSON-lDJSON-lD
JSON-lD
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Mitos do PHP
Mitos do PHPMitos do PHP
Mitos do PHP
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvements
 
HTML CSS JavaScript 行動應用程式解決方案
HTML CSS JavaScript 行動應用程式解決方案HTML CSS JavaScript 行動應用程式解決方案
HTML CSS JavaScript 行動應用程式解決方案
 
PHP7 - For Its Best Performance
PHP7 - For Its Best PerformancePHP7 - For Its Best Performance
PHP7 - For Its Best Performance
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...
Badoo в облаках. Решение для запуска cli-скриптов в облаке собственной разраб...
 
PHP 7
PHP 7PHP 7
PHP 7
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向
 
Weaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryWeaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP library
 
工作坊簡介
工作坊簡介工作坊簡介
工作坊簡介
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 

Similar to PHP7 - The New Engine for old good train

PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5julien pauli
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourSoroush Dalili
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
Automating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server apiAutomating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server apiYonni Mendes
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDBIgor Donchovski
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6Damien Seguy
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Jan Helke
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Review unknown code with static analysis Zend con 2017
Review unknown code with static analysis  Zend con 2017Review unknown code with static analysis  Zend con 2017
Review unknown code with static analysis Zend con 2017Damien Seguy
 
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Ontico
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworksKirk Madera
 
High Performance Rails with MySQL
High Performance Rails with MySQLHigh Performance Rails with MySQL
High Performance Rails with MySQLJervin Real
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)Nexcess.net LLC
 

Similar to PHP7 - The New Engine for old good train (20)

PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Automating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server apiAutomating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server api
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDB
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Review unknown code with static analysis Zend con 2017
Review unknown code with static analysis  Zend con 2017Review unknown code with static analysis  Zend con 2017
Review unknown code with static analysis Zend con 2017
 
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
 
High Performance Rails with MySQL
High Performance Rails with MySQLHigh Performance Rails with MySQL
High Performance Rails with MySQL
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

PHP7 - The New Engine for old good train

  • 1. PHP 7 - New Engine For The Good Old Train @laruence
  • 2. About Me •  Author of Yaf, Yar, Yac, Taint, Lua, etc •  Maintainer of APC, Zend Opcache, Msgpack, etc •  Chief software architect At Weibo since 2012 •  PHP core developer since 2011 •  Zend consultant since 2013 •  Core author of PHP7
  • 3. About PHP •  20 years history •  Most popular Web service program language •  Over 82% sites are use PHP as server program language
  • 4. PHP 7 New Features
  • 5. PHP 7? •  PHP NG – Engine Refactor - performance improvements •  Abstarct Syntanx Tree •  Int64 Improvement •  Uniform variable syntax •  Native TLS •  Consistently foreach behaviors •  New <=>, **, ?? operaters •  Return Type Declarations •  Scalar Type Declarations •  Exceptions in Engine •  And Dozens features…
  • 6. Abstract Syntax Tree PHP Parser AST Opcodes Execution PHP Parser Opcodes Execution •  PHP5 •  PHP7
  • 7. Int64 Improvement •  >2GB string •  >2GB file uploading •  Fully 64bits intgers cross platforms
  • 8. Uniform Variables Syntanx •  $foo()['bar']() •  $foo['bar']::$baz •  foo()() – (foo())() •  $foo->bar()::baz() •  (function() { ... })() •  $this->{$name}() •  [$obj, 'method']() •  Foo::$bar['baz']() PHP5: Foo::{$bar['baz']}() PHP7: (Foo::$bar)['baz']()
  • 9. Return Type Declarations •  function foo(): array { return []; } •  interface A { static function make(): A; } •  function foo(): DateTime { return null; } PHP Fatal error: Return value of foo() must be an instance of DateTime, null returned
  • 10. Scalar Type Declarations •  function foo(int num) •  function bar (string name) •  function foobar() : float {} •  function add(int l, int r) : int {} •  class A { public function start (bool start) {} }
  • 11. Exceptions in Engine •  Use of exceptions in Engine try { non_exists_func(); } catch (EngineException $e) { echo "Exception: {$e->getMessage()}n"; }   Exception: Call to undefined function non_exists_func() •  Uncaught Exception result to FATAL ERROR non_exists_func(); PHP Fatal error: Call to undefined function non_exists()
  • 12. PHP NG (Next Generation)
  • 13. PHP Performance Evaluation 2.991 3.045 3.102 3.762 5.318 6.527 13.424 0 2 4 6 8 10 12 14 16 PHP-5.6 PHP-5.5 PHP-5.4 PHP-5.3 PHP-5.2 PHP-5.1 PHP-5.0 bench.php(sec)
  • 14. PHP Performance Evaluation 112 110 107 82 75 0 0 0 20 40 60 80 100 120 PHP-5.6 PHP-5.5 PHP-5.4 PHP-5.3 PHP-5.2 PHP-5.1 PHP-5.0 Wordpress 3.6 home page qps
  • 15. PHP Performance Evaluation •  ~5 times faster from 5.0 to 5.6 in bench •  ~2 times faster from 5.0 to 5.6 in real-life apps •  No big performance improvement after 5.4 •  Zend VM is already highly optimized
  • 16. •  Generate optimized codes based on run-time types inference PHP Just In Time Compiler? PHP Parser Opcodes TypeInf JIT Bytecodes Execution
  • 17. PHP Just In Time Compiler? •  We created a POC of JIT compiler based on LLVM for PHP-5.5 in 2013 •  ~8 times speedup on bench.php •  Negligible speedup on real-life apps (1% on Wordpress) •  https://github.com/zendtech/php-src/tree/zend-jit
  • 19. •  21% CPU time in meory manager •  12% CPU time in hash tables operations •  30% CPU time in internal functions •  25% CPU time in VM Wordpress profile
  • 20. New Generation •  It’s a refactoring •  Main goal — achieve new performance level and make base for future improvements •  No new features for users (only internals) •  Keep 100% compatibility in PHP behavior •  May 2014 we opened the project
  • 22. ZVAL •  No refcount for scalar types •  zvals are always pre-allcocated or allocated in stack(nomore MAKE_STD_ZVAL and ALLOC_ZVAL) •  String using refcout instead of copy (zend_string) •  gc_info, temporary_variables, should_free_var, cache_slot all in zval •  New types: IS_TRUE, IS_FALSE, IS_REFERENCE, IS_INDIRECT Zend VM execute data Internal Functions zval zval zval zval zval Uesr land zend array zval zval zval zval zval stack zvals zval zval zval zval zval
  • 23. •  IS_UNDEF •  IS_NULL •  IS_FALSE •  IS_TRUE •  IS_LONG •  IS_DOUBLE •  IS_STRING •  IS_ARRAY •  IS_OBJECT •  IS_RESOURCE •  IS_REFERENCE ZVAL v28u4 tAp4 u2f826s 0 8 32 63 IS_S.RING/IS_ARRA0/IS_OBJEC./IS_RESRO/CE/... r4f3ount 63_infotAp4 0 32 63 f826s 48
  • 24. •  IS_NULL •  IS_FALSE •  IS_TRUE •  IS_LONG •  IS_DOUBLE ZVAL NON REFCOUNED value type u2flags 0 8 32 63
  • 25. •  IS_STRING •  IS_ARRAY •  IS_OBJECT •  IS_RESOURCE •  IS_REFERENCE ZVAL REFCOUNED IS_S.RING/IS_ARRA0/IS_OBJEC./IS_RESRO/CE/... r4f3ount 63_infotyp4 0 32 63 f826s 48
  • 26. •  New Internal Type: Zend String IS_STRING •  IS_STRING_PERSISTENT •  IS_STR_INTERNED •  IS_STR_PERMANENT •  IS_STR_CONSTANT un3igned l0ng ha3h_6alue 2efc0un4 gc_inf04y1e 0 32 63 flag3 48 3i8e_4 342ing_len cha2[  ] 6al
  • 27. •  New Internal Type: Zend Array IS_ARRAY •  IS_ARRAY_IMMUTABLE refcount gc_infotype 0 32 63 flags 48 nTableMasku Bucket *arData nNumUsed nNumOfElements .....
  • 28. IS_OBJECT •  Zend Object •  IS_OBJ_APPLY_COUNT •  IS_OBJ_DESTRUCTOR_CALLED •  IS_OBJ_FREE_CALLED zend_class_entry *ce refcount gc_infotype 0 32 63 flags 48 zend_object_handlers *handlers zend_array *properties zend_array *guarders zval *properties_table[1]
  • 29. •  New Internal Type: Zend Reference •  Reference is type IS_REFERENCE refco0nt gc_infot2pe 0 3   63 flags 48 3val val0e
  • 30. HashTable – PHP 5 HashTable nTableMasknTableSize 0 8 32 63 pInternalPointer nNumOfElem nNextFreeElement Bucket * pListHead pListTail arBuckets pDestructor Bucket * Bucket * ....... Bucket hashval nKeyLength pDataPtr pData pListNext pListPrev pNext pLast arKey Bucket hashval nKeyLength pDataPtr pData pListNext pListPrev pNext pLast arKey Zval value type
  • 31. Zend Array – PHP 7 zend_array refcounted 0 8 32 63 u arData idx idx Bucket 0 nTableMask nNumUsed nNumOfElem nTableSize InternalPointer pNextFreeElement pDestructor ....... hashval key zval Bucket 1 hashval key zval Bucket 2 ......
  • 32. Zend Array(HashTable) •  Values of arrays are zval by default •  HashTable size reduced from 72 to 56 bytes •  Bucket size reduced from 72 to 32 bytes •  Memory for all Buckets is allocated at once •  Bucket.key now is a pointer to zend_string •  Values of array elements are embedded into the Buckets •  Improved data locality => less CPU cache misses
  • 33. Function calling convention – PHP5 •  function add ($a, $b) { return $a + $b; } add(1, 2); send_val 1 send_val 2 do_fcall add (2) 1 2 call frame(add) opcodes(main): call frame(main) recv 1 $a recv 2 $b zend_add $a, $b ~0 opcodes(add): zend_return ~0 1 2 3 vm stack
  • 34. Function calling convention – PHP7 •  function add ($a, $b) { return $a + $b; } add(1, 2); send_val 1 send_val 2 do_fcall 2 call frame(add) init_fcall add call frame(main) recv 1 $a recv 2 $b zend_add $a, $b ~0 opcodes(add): zend_return ~0 1 2 3 vm stack
  • 35. Fast Parameters Parsing APIs •  ~5% of the CPU time is spent in zend_parse_parameters() •  For some simple functions the overhead of zend_parse_parameters() is over 90%
  • 36. Inline Frequently used simple functions •  call_user_function(_array) => ZEND_INIT_USER_CALL •  is_int/string/array/* etc => ZEND_TYPE_CHECK •  strlen => ZEND_STRLEN •  defined => ZEND+DEFINED •  …
  • 37. Faster zend_qsort •  Refactor zend_qsort for better performance •  Hybrid Sorting Algo(Quick Sort and Selection Sort) •  <16 elements do stable sorting •  $array = array(0 => 0, 1=>0); asort($array); •  PHP5: array(1=>0, 0=>0); •  PHP7: array(0=>1, 1=>0);
  • 38. New Memory Manager •  Friendly to moder CPU cache •  less CPU cache misses •  Faster builtin types allocating •  ~5% CPU time reduce in wordpress homepage
  • 39. Dozens of other improvements •  Fast HashTable iteration APIs •  Immutable array •  Array duplication optimization •  PCRE with JIT •  BIND_GLOBAL instead of FETCH and ASSIGN_REF •  More specifical DO_UCALL and DO_ICALL •  Global registers for execute_data and opline(GCC-4.8+) •  ZEND_ROPE_* for faster string concating •  ZEND_CALL_TRAMPOLINE for faster__call/__callstatic •  Dozens logic optimizations •  ….
  • 41. Wordpress profiled (2015-04-14) •  >50% CPU IRs reduced •  5% CPU time in meory manager •  12% CPU time in hash tables operations
  • 42. PHP7 Performance – Benchmark (2014-04-14) 1.186 2.991 3.045 3.102 3.762 5.318 6.527 13.424 0 2 4 6 8 10 12 14 16 PHP-7 PHP-5.6 PHP-5.5 PHP-5.4 PHP-5.3 PHP-5.2 PHP-5.1 PHP-5.0 bench.php(sec)
  • 43. PHP7 Performance – Reallife App (2015-04-14) 311 112 110 107 82 75 0 0 0 50 100 150 200 250 300 350 PHP-7 PHP-5.6 PHP-5.5 PHP-5.4 PHP-5.3 PHP-5.2 PHP-5.1 PHP-5.0 wordpress 3.0.1 home page qps
  • 44. PHP7 Performance (By Rasmus 2015-04-21)
  • 48. Always Do Your Own Benchmark
  • 49. PHP 7 Next •  Keep 99.99% compatible with PHP5 •  Keep Improving performance •  Port common used PECL extensions (memcached, redis etc) •  Release PHP 7 (oct 2015) •  Restart JIT (Sep 2014)
  • 50. Links •  phpng:_Refactored_PHP_Engine_with_Big_Performance_Improveme nt: http://news.php.net/php.internals/73888 •  PHPNG RFC: https://wiki.php.net/phpng •  PHPNG Implementation details: https://wiki.php.net/phpng-int •  Upgrading PHP extensions from PHP5 to PHPNG: https://wiki.php.net/phpng-upgrading •  Zeev <Benchmarking PHPNG>: http://zsuraski.blogspot.co.il/2014/07/benchmarking-phpng.html •  Rasmus <SPEEDING UP THE WEB WITH PHP 7>: http://talks.php.net/fluent15#/