Those slides, inspired by the works and ideas of many, are a state of what PHP gets in upgrades as of Q1 2018.
Market share and evolution.
PHP 7.0
PHP Ecology
PHP 7.3 Cool stuff.
11. zval size reduced from 24 to 16 bytes
Hashtable size reduced from 72 to 56 bytes
Hashtable bucket size reduced from 72 to 32 bytes
Immutable array optimization
$a = [];
for($i=0; $i < 100000;$i++) {
$a[] = ['abc','def','ghi','jkl','mno','pqr'];
}
echo memory_get_usage(true);
// PHP 5.x 109M
// PHP 7.0 42M no opcache
// PHP 7.0 6M with opcache enabled
12. All variables in PHP are represented by one structure, the zval:
typedef struct _zval_struct {
zvalue_value value; /* variable value */
zend_uint refcount__gc; /* reference counter */
zend_uchar type; /* value type */
zend_uchar is_ref__gc; /* reference flag */
} zval;
The zval_value is a union which can represent all types a variable may hold:
typedef union _zvalue_value {
long lval; /* long value */
double dval; /* double value */
struct {
char *val;
int len; /* this will always be set for strings */
} str; /* string (always has length) */
HashTable *ht; /* an array */
zend_object_value obj; /* stores an object store handle, and handlers
*/
} zvalue_value;
http://php.net/manual/en/internals2.variables.intro.php
14. for ($i = 0; $i < 1000; $i++) {
$var[] = [
0 => 'SymfonyBundleFrameworkBundleEventListenerSessionListener',
1 => 'SymfonyComponentHttpFoundationSessionStorageNativeSessionStorage',
/* ... you can add more there :) */
];
}
// PHP 5: 27 MB of RAM
// PHP 7: 36 KB of RAM
$a = 'value';
/* Don't do that! */
$ar = ['foo', 'bar', 42, $a];
/* But prefer that */
$ar = ['foo', 'bar', 42, 'value'];
https://blog.blackfire.io/php-7-performance-improvements-immutable-arrays.html
15. New memory allocator similar to jemalloc
Faster hashtable iteration API
Array duplication optimization
PCRE JIT enabled by default
Precomputed string hashes
Fast ZPP (ZendParseParameters) implementation
Faster stack-allocated zvals (instead of heap)
Optimized VM calling
Global register variables with gcc 4.8+
plus hundreds of micro-optimizations
(don’t ask me, I got no clue about most of them :D )