SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
As a result of an engine rewrite with focus on more efficient data structures, PHP 7 offers much improved performance and memory usage. This session describes important aspects of the new implementation and how it compares to PHP 5. A particular focus will be on the representation of values, arrays and objects.
As a result of an engine rewrite with focus on more efficient data structures, PHP 7 offers much improved performance and memory usage. This session describes important aspects of the new implementation and how it compares to PHP 5. A particular focus will be on the representation of values, arrays and objects.
37.
$i = 42;
$j = $i;
7
$i value = 42
LONG
$j value = 42
LONG
38.
$i = 42;
$j = $i;
$k = $i;
7
$i value = 42
LONG
$j value = 42
LONG
$k value = 42
LONG
39.
$s = “foobar”;
7
$s value
STRING
refcount = 1 type_info
hash = 0x80000652FDE460BE
len = 6
f o o b a r 0
40.
$s = “foobar”;
$t = $s;
7
$s value
STRING
$t value
STRING refcount = 2 type_info
hash = 0x80000652FDE460BE
len = 6
f o o b a r 0
41.
$s = “foobar”;
$t = $s;
$u = $s;
7
$s value
STRING
$t value
STRING
$u value
STRING
refcount = 3 type_info
hash = 0x80000652FDE460BE
len = 6
f o o b a r 0
42.
7
refcount type_info
hash
len (size_t)
A B C 0
refcounted header
43.
7
refcount type_info
hash
len (size_t)
A B C 0
refcounted header
type flags gc_info
44.
7
refcount type_info
hash
len (size_t)
A B C 0
refcounted header
type flags gc_info
INTERNED
etc.
64.
7
hash
key
value
type_info next
refcount type_info
hash
len
f o o 0
zend_string
65.
7
hash
key
value
type_info next
hash
key
value
type_info next
hash
key
value
type_info next
66.
7
hash
key
value
type_info next
hash
key
value
type_info next
hash
key
value
type_info next
[0]
[1]
[2]
[3]
67.
7
hash
key
value
type_info next
hash
key
value
type_info next
hash
key
value
type_info next
[0] = -1
[1] = -1
[2] = -1
[3] = -1
$a = [];
numUsed = 0
68.
7
hash
key
value = 42
LONG next = -1
hash
key
value
type_info next
hash
key
value
type_info next
[0] = -1
[1] = 0
[2] = -1
[3] = -1
“foo”
$a = [];
$a[“foo”] = 42;
“foo”
numUsed = 1
69.
7
hash
key
value = 42
LONG next = -1
hash
key
value = 24
LONG next = -1
hash
key
value
type_info next
[0] = -1
[1] = 0
[2] = -1
[3] = 1
“foo”
$a = [];
$a[“foo”] = 42;
$a[“bar”] = 24; “foo”
“bar”
“bar”
numUsed = 2
70.
7
hash
key
value = 42
LONG next = 2
hash
key
value = 24
LONG next = -1
hash
key
value = 3.141
DOUBLE next = -1
[0] = -1
[1] = 0
[2] = -1
[3] = 1
“foo”
$a = [];
$a[“foo”] = 42;
$a[“bar”] = 24;
$a[“xyz”] = 3.141;
“foo”
“bar”
“bar”
“xyz”
“xyz”
71.
7
hash
key
value
UNDEF next = -1
hash
key
value = 24
LONG next = -1
hash
key
value = 3.141
DOUBLE next = -1
[0] = -1
[1] = 2
[2] = -1
[3] = 1
$a = [];
$a[“foo”] = 42;
$a[“bar”] = 24;
$a[“xyz”] = 3.141;
unset($a[“foo”]);
“bar”
“bar”
“xyz”
“xyz”
72.
7
hash
key
value
type_info next
hash
key
value
type_info next
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
73.
7
hash
key
value
type_info next
hash
key
value
type_info next
[0] [1]
[2] [3]
[4] [5]
[6] [7]
74.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
75.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
76.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
data / hash pointer
numUsed
77.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed
tableSize
tableMask = -tableSize
78.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed
tableSize
1010111010110110
tableMask = -tableSize
79.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed
tableSize
1010111010110110
| 1111111111100000
tableMask = -tableSize
80.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed
tableSize
1010111010110110
| 1111111111100000
= 1111111111110110 = -10
tableMask = -tableSize
81.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed numElems
tableSize
nextFreeElement
82.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
tableMask
data / hash pointer
numUsed numElems
tableSize internalPtr
nextFreeElement
destructor
83.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
flags tableMask
data / hash pointer
numUsed numElems
tableSize internalPtr
nextFreeElement
destructor
flags applyCnt iterCnt
84.
7
hash
key
value
type_info next
hash
key
value
type_info next
[-8] [-7]
[-6] [-5]
[-4] [-3]
[-2] [-1]
hash
data
refcount type_info
flags tableMask
data / hash pointer
numUsed numElems
tableSize internalPtr
nextFreeElement
destructor
flags applyCnt iterCnt
PACKED
etc.
85.
7
hash
key
value
type_info next
hash
key
value
type_info next
data
refcount type_info
flags tableMask
data pointer
numUsed numElems
tableSize internalPtr
nextFreeElement
destructor
flags applyCnt iterCnt
PACKED
etc.
88.
5
handle (ID)
handlers
zval value
handler table
object store bucket
89.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
object store bucket
90.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
object
object store bucket
actual object
91.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
object
refcount
object store bucket
actual object
92.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
object
dtor()
free_storage()
clone()
refcount
object store bucket
actual object
93.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
object
dtor()
free_storage()
clone()
handlers
refcount
gc_root
object store bucket
actual object
94.
5
handle (ID)
handlers
zval value
…
read_prop()
write_prop()
…
D V ac
object
dtor()
free_storage()
clone()
handlers
refcount
gc_root
object store bucket
actual object
96.
5
object store bucket
ce
standard object
zend_class_entry
97.
5
object store bucket
ce
properties
standard object
zend_class_entry
HashTable for
dynamic properties
98.
5
object store bucket
ce
properties
properties_table
standard object
zend_class_entry
HashTable for
dynamic properties
[0] (stores $prop1)
[1] (stores $prop2)
[2] (stores $prop3)
zval
zval
zval
99.
5
object store bucket
ce
properties
properties_table
guards
standard object
zend_class_entry
HashTable for
dynamic properties
[0] (stores $prop1)
[1] (stores $prop2)
[2] (stores $prop3)
zval
zval
zval
HashTable for
__get etc. guards
100.
5
object store bucket
ce
properties
properties_table
guards
custom extension
for internal object
standard object
zend_class_entry
HashTable for
dynamic properties
[0] (stores $prop1)
[1] (stores $prop2)
[2] (stores $prop3)
zval
zval
zval
HashTable for
__get etc. guards
101.
7
zend_object *
refcount type_info
ce
properties
zend_class_entry
HashTable for
dynamic properties
102.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
zend_class_entry
HashTable for
dynamic properties
handler table
103.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
zend_class_entry
HashTable for
dynamic properties
handler table
object store
104.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
zend_class_entry
HashTable for
dynamic properties$prop1 zval
$prop2 zval
$prop3 zval
handler table
object store
105.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
zend_class_entry
HashTable for
dynamic properties
HashTable for
__get etc. guards
guards zval
$prop1 zval
$prop2 zval
handler table
object store
106.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
zend_class_entry
HashTable for
dynamic properties
HashTable for
__get etc. guards
guards zval
$prop1 zval
$prop2 zval
handler table
object store
ext. for internal objects
107.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
zend_class_entry
HashTable for
dynamic properties
HashTable for
__get etc. guards
guards zval
$prop1 zval
$prop2 zval
handler table
object store
ext. for internal objects offset
108.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
guards zval
$prop1 zval
$prop2 zval
object store
ext. for internal objects
offset
…
handlers table
offset
109.
7
zend_object *
refcount type_info
handle
ce
handlers
properties
value
type_info
value
type_info
value
type_info
guards zval
$prop1 zval
$prop2 zval
object store
ext. for internal objects
offset
free()
dtor()
clone()
…
handlers table
offset