Opcache: Introduce ABI-based versioning for file cache portability #19123
+227
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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