zeriyoshi · GitHub

RFC: https://wiki.php.net/rfc/impl_user_cache

This PR introduces a new built-in extension, ext-user_cache, to PHP.
It replaces the earlier OPcache Static Cache (#22534) and OPcache User Cache (#22052) proposals.

It is a refined version whose design has been completely rethought and reimplemented from scratch, rather than carried over from the previous proposals.

The previous discussion of the OPcache Static Cache can be found on the internals mailing list (externals.io): https://externals.io/message/130912

ext-user_cache provides high-performance caching that persists across request boundaries.

Values are stored in and retrieved from pre-allocated shared memory (SHM) through one of the following paths:

  • Scalar values are copied directly.
  • Objects that can use a shared graph representation are converted to that representation and copied.
  • Internal or extension classes that have a safe direct-conversion (safe direct) path (e.g. ext-date, ext-spl) are converted to a shared graph representation and copied.
  • Values with certain magic methods such as __serialize are serialized with a fast internal serializer and then copied.
  • Unsupported values result in an error.

The extension is enabled by default and enforces appropriate security boundaries for each SAPI. Even when it is disabled, libraries can continue to use it transparently; they simply gain no caching benefit.

The extension is designed specifically for fetch-heavy workloads, so its write performance is lower than that of existing third-party extensions. However, I believe this trade-off is acceptable given the nature of caching.

Detailed benchmarks and their test suites are available here:

Read the original on github.com ↗