# Bytecode Execution

> Section in “Introduction › Behind the Scenes” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/introduction/behind-the-scenes/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.

---

Previous: [Compiler](https://php7explained.com/introduction/behind-the-scenes/compiler/index.html.md) | Next: [Bytecode Caching](https://php7explained.com/introduction/behind-the-scenes/bytecode-caching/index.html.md)
