Skip to content

[RFC] OPcache User Cache Implementation#22534

Open
zeriyoshi wants to merge 1 commit into
php:masterfrom
colopl:opcache_user_cache
Open

[RFC] OPcache User Cache Implementation#22534
zeriyoshi wants to merge 1 commit into
php:masterfrom
colopl:opcache_user_cache

Conversation

@zeriyoshi

@zeriyoshi zeriyoshi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Re-implementation of #22052 (OPcache Static Cache)

Overview

This implementation includes userland cache backend of OPcache.

Adds the \Opcache\UserCache class, which provides a fast, object-based user-land caching system.

Caching system does not serialize objects and scalar values; instead, it uses a shared graph representation to provide a cache that can be quickly retrieved across requests.

This method significantly reduces the processing overhead associated with serializing and deserializing objects in extensions such as APCu, enabling high-speed cache operations. However, since creating a shared graph requires a detailed traversal of the object tree structure, write workloads are generally slower than with APCu.

Also, care must be taken when handling objects intended for serialization. Objects do not involve serialization or deserialization, so they do not execute magic methods such as __serialize or __unserialize. As a result, the state of some classes that use spl_object_hash or similar functions may become corrupted. To mitigate this, if a property contains an object hash when it is stored, the process includes writing a new value to that property when it is fetched.

Safe-Direct path

Objects defined in the C layer—or objects that inherit from these—cannot generally be cached

However, this is possible for objects that implement the Safe-Direct path. In this implementation, this capability has been implemented for certain classes in ext-date and ext-spl.

This provides a means to safely supplement and restore the memory data held by internal objects.

Performance

Running on OrbStack with Ubuntu 24.04 (arm64) on MacBook Air (M4, 32GB). Test harness is available on https://github.com/colopl/php-opcache_user_cache_benchmark_harness

HTML Report: https://github.com/colopl/php-opcache_user_cache_benchmark_harness/blob/main/BENCH_RESULT.html
View GH Pages: https://colopl.github.io/php-opcache_user_cache_benchmark_harness/

API

Please read RFC (WIP)

Closes: #22052

@zeriyoshi zeriyoshi force-pushed the opcache_user_cache branch from b64f44b to 0dbb737 Compare July 1, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant