Bytecode Execution
Hundreds of optimizations were implemented for the executor, the part of the PHP runtime that executes PHP bytecode. Most of these optimizations revolve around leveraging improvements introduced in modern C compilers, utilizing CPU caches more effectively, allocating memory more efficiently, and handling hash tables better.
The zval
, for instance, the data structure used
internally by PHP to represent variables, has been optimized. A
significant difference between how zval
s are stored in
PHP 5 and PHP 7 is the fact that a zval
in PHP 7 no
longer carries information needed for the garbage collector. This
means that zval
s for simple values such as booleans,
integers, or floats no longer require any allocation. The overhead
of storing the reference counting information that is necessary for
the garbage collector is now only incurred when it is needed: for
arrays, objects, strings, and resources. A zval
is no
longer allocated on the heap but instead embedded into the
heap-allocated structure such as a hash table bucket, for instance.
This means that less indirection is required when a
zval
is accessed.
The hash table implementation used internally by PHP to represent symbol tables or the data stored in an array, for instance, has been completely reengineered for PHP 7 to use smaller data structures that require fewer memory allocations. PHP 7 now also uses packed hash tables to optimize for the common use case of integer-indexed arrays that have no gaps in the sequence of their keys.