[php-src] PR #19123: Opcache: Introduce ABI-based versioning for file cache portability
| From: | iamacarpet | Date: | Mon, 14 Jul 2025 10:17:16 +0000 |
| Subject: | [php-src] PR #19123: Opcache: Introduce ABI-based versioning for file cache portability | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-32432@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/19123
Author: iamacarpet
Hello @dstogov and team,
This PR proposes a new versioning mechanism for the file-based opcache to improve its **portability
across different patch versions of PHP (e.g., 8.5.x)** and minor system library changes.
### The Problem
Currently, the file cache is versioned using
zend_system_id, which is highly sensitive
to minor changes in the environment, such as updates to system libraries or patch-level changes in
the PHP version itself.
This fragility makes pre-generated, read-only opcaches difficult to use in modern containerized
platforms like Google App Engine and Cloud Run. These platforms often perform automatic base image
updates, which can change zend_system_id and invalidate an otherwise perfectly valid
opcache, negating the performance benefits.
### The Proposed Solution
To address this, this change introduces an "ABI hash" for the file cache. During the build
process, it calculates a CRC32 checksum of the header files that define the core data structures
used by opcache (e.g., zend_op, zval, zend_string,
zend_function, zend_class_entry, etc.).
This hash is then used as part of the cache key instead of the more volatile
zend_system_id. The result is a cache key that only changes when the underlying data
structures (the ABI) actually change, which typically only happens between minor PHP versions (e.g.,
8.5 vs 8.6).
### Benefits
* **Improved Portability:** Opcache file caches become portable across builds with identical ABIs,
even if the PHP patch version or system libraries differ.
* **Enhanced Performance on Managed Platforms:** This significantly improves the effectiveness of
pre-warmed, read-only caches in environments with automatic base image updates, leading to better
cold-start performance and reduced CPU usage.
This change is a continuation of the work started in #16551 and #16979 to optimize opcache for
modern, ephemeral environments.
I believe a change of this nature will likely require an RFC. I'm happy to start that process
and would appreciate any initial feedback on this approach.
Thank you for your time and consideration.
Regards,
iamacarpet