Production & Performance
What the framework costs at runtime, and how to build, tune and ship the cache so that production pays only for the calls that have behaviors.
The framework compiles your classes with their behaviors once and stores the result as plain PHP files. From then on those files are served like any other code: OPcache caches them, Composer loads them, and no parser, reflection or eval() runs at request time. A production request on a warm cache reads one metadata file, hands the generated classes to Composer and pays only for the calls that are actually intercepted. Methods and properties without behaviors cost nothing.
This page gives the measured numbers, explains where the cost comes from, and shows how to ship the cache: warm-up at deploy time, OPcache, Composer, Docker and Kubernetes. Kernel options are described in Configuration. A visual summary is on the Performance feature page.
Measured costs
Section titled “Measured costs”All numbers on this page come from the upstream docs/performance.md of goaop/framework. They were measured on one machine, so read them as ratios between modes. The ratios are what carries over to other machines.
Benchmark setup
Section titled “Benchmark setup”- A small shop application: about 250 files below the include paths (94 compiled classes), 120 library classes outside of them, and 6 behavior classes with
#[Before],#[Around],#[AfterThrowing]and property behaviors. - One request places 50 orders. That makes ~2,600 intercepted method calls and ~950 intercepted property accesses.
- PHP 8.5.12 NTS, 4 CPUs, OPcache in shared memory,
opcache.jit=disable,opcache.file_update_protection=0.
The full method is in Reproducing the benchmarks below.
Request time by mode
Section titled “Request time by mode”The three cache states:
- hot: compiled cache present, OPcache filled. The steady state of a production worker.
- warm: compiled cache present, OPcache empty. A freshly started PHP-FPM or a new pod.
- cold: nothing cached yet. The first request compiles every class it loads.
| Mode | hot | warm | Peak memory (hot) |
|---|---|---|---|
debug => false + PREBUILT_CACHE |
5.4 ms | 59 ms | 1.3 MB |
debug => false |
5.5 ms | 62 ms | 1.3 MB |
debug => true |
13.0 ms | 63 ms | 2.2 MB |
| Same application without the framework (behaviors do not run) | 2.1 ms | 36 ms | 0.7 MB |
- ~3,500 interceptions with real behavior bodies (logging, cache lookups, timers) add ~3.3 ms to the request. Booting the kernel takes ~0.15 ms of it.
- One intercepted call costs about a third of a microsecond, and every further behavior on it ~70 ns.
- The whole cache is built in under half a second with
cache:warmup:aop. A 2,000-file application takes 1.1 s with 4 workers. - Containers start hot. With a primed OPcache file cache, the first request of a new PHP-FPM takes 19 ms instead of 71 ms. With preloading on top it takes 10 ms, the same as the plain application without the framework (9 ms).
Cost per call
Section titled “Cost per call”These figures use empty behaviors, so they measure only the framework’s own work: the call context, the chain of interceptors and the call of the original method.
| Call | Overhead per call |
|---|---|
| Method or property without a behavior in a compiled class | 0 |
Method with one #[Before] or #[Around] |
~0.33 µs |
Method with three #[Around] |
~0.48 µs |
Static method with one #[Around] |
~0.34 µs |
Property read with one #[Around] |
~0.22 µs |
Property write with one #[Around] |
~0.26 µs |
A million intercepted calls cost about a third of a second. A typical request with a few hundred interceptions pays a fraction of a millisecond.
CLI processes
Section titled “CLI processes”Every CLI process starts with an empty OPcache. A primed opcache.file_cache makes short-lived commands start almost as fast as a hot web request.
| Script time per process | OPcache off | OPcache on (memory only) | opcache.file_cache, primed |
|---|---|---|---|
PREBUILT_CACHE |
33 ms | 69 ms | 21 ms |
debug => false |
30 ms | 69 ms | 22 ms |
| Without the framework | 19 ms | 34 ms | 10 ms |
What costs what
Section titled “What costs what”Members without behaviors
Section titled “Members without behaviors”The proxy overrides only the members that have behaviors. Every other method and property is your original code and runs at full speed: the overhead is 0. Classes that no matching rule selects are not compiled at all.
Intercepted calls and stacked behaviors
Section titled “Intercepted calls and stacked behaviors”Each intercepted method declares one static call context:
static $__joinPoint = InterceptorInjector::forMethod(...)The call context and its list of interceptors are built on the first call. Every later call is a single $__joinPoint->__invoke($this, [$args]). That list holds first-class callables that point straight at the methods of your behavior classes, so there is no lookup of behaviors, no reflection and no __call().
The first behavior on a method costs ~0.33 µs. Each further behavior adds ~70 ns, so three #[Around] behaviors cost ~0.48 µs. A static method with one #[Around] costs ~0.34 µs.
Reflection for behaviors (getMethod(), getField()) is created only when a behavior asks for it.
Property access
Section titled “Property access”Property interception compiles to native PHP 8.4 get and set hooks on the proxy. There is no __get() or __set() magic and no reflection per access. A property read with one #[Around] costs ~0.22 µs, a write ~0.26 µs.
Kernel boot
Section titled “Kernel boot”Booting the kernel takes ~0.15 ms in the benchmark. The framework’s services, the transformers and your behavior classes are registered as factories, one array write each. Nothing is autoloaded, reflected or created at boot, so a warm request never loads the parser, the matching-rule grammar, the matcher of behaviors or the transformers.
- The cache index (
CachePathManager) is the only service built ininit(), because the autoloader reads the class map right away. - Behavior classes are created on the first call of one of their behaviors, as PHP 8.4 native lazy objects. The compile step and the cache warm-up never create a behavior class; they only read it.
- Production arms no registration listener. Debug mode tracks behavior-class files for changes through a listener that resolves the files through Composer without loading the classes.
- The parse table of the matching-rule grammar is generated PHP, and rules are parsed on first use only.
Cold and warm starts
Section titled “Cold and warm starts”A warm request (compiled cache present, OPcache empty) takes 59 ms with PREBUILT_CACHE against 36 ms for the plain application. You shorten it with a primed opcache.file_cache and preloading, see Docker and Kubernetes.
A cold request compiles every class it loads. With a cache built at deploy time and PREBUILT_CACHE, a production request never compiles.
Compile time
Section titled “Compile time”Compilation happens once, at deploy time.
- The cache of the benchmark application is built in under half a second.
- A 2,047-file application took 2.2 s with one worker and 1.1 s with 4 workers on 4 CPUs.
- Every parsed file kept in memory while compiling takes ~0.2 MB. The
parsedFilesLimitkernel option (default100) bounds how many are kept.
What keeps compilation fast:
- The cache hit path parses nothing. A fresh record is served as the cached content before any transformer exists. The stream filter and the transformer chain are built on the first miss only.
- All rewriting rules share one syntax tree walk. A rule whose source marker does not occur in the file is skipped, and a file without any applicable rule is not walked at all. That is the case for most files.
- Your behavior classes switch the machinery on.
newexpressions are rewritten only while aninitialization(...)rule is registered. Function proxies exist only for function rules. - The behavior-class check, which reflects every ancestor, runs only for classes that have behaviors.
- The behaviors of a behavior class are cached as a plain PHP file of static constructor expressions, about twice as fast to load as
unserialize(). - Proxies are built as syntax trees and printed once (−43 % compile time). The generated trait is produced by token edits that keep your line numbers for Xdebug.
What a production request does
Section titled “What a production request does”| Step | debug => false (+ PREBUILT_CACHE) |
debug => true |
|---|---|---|
Kernel init() |
options, container, service factories (nothing is created) | the same, plus the kernel and behavior-class files tracked for changes |
_include.cache (class map, skip set) |
one include, served from OPcache, no stat() of the cache directory |
the same |
| Compiled class | Composer’s class map → cached file, from OPcache | freshness check, then the stream filter, so Xdebug breakpoints and magic constants point at your original files |
| Untransformed class below the include paths | skip set → the original file, from OPcache | freshness check → the original file, from OPcache |
| Parser, transformers, stream filter | never loaded | stream filter registered, no transformer built |
| A changed source file | the cache built at deploy time is served as it is | recompiled on the next request |
File-system calls of one hot request, counted by the profiler:
| Call | PREBUILT_CACHE |
debug => false |
debug => true |
Without the framework |
|---|---|---|---|---|
filemtime / filesize |
0 | 0 | 323 / 239 | 0 |
file_get_contents |
0 | 0 | 94 | 0 |
file_exists (Composer PSR-4) |
307 | 307 | 412 | 357 |
A production request checks no source file. It even needs fewer Composer lookups than the plain application, because the generated classes come straight from the class map. An optimized Composer class map removes the remaining lookups, see Composer autoloader.
Two more details of the runtime index:
_include.cacheholds only what a request needs: the class map, the skip set and the include map. The full build records live in_transformation.cache, which production never reads.- Both metadata files are
var_export()ed arrays with__DIR__-relative paths. OPcache keeps them immutable in shared memory, so including them copies nothing, and the cache stays valid when the application directory moves.
Debug mode is made for development. Its hot requests take ~13 ms in the benchmark, production ~5.5 ms. Debug mode still includes a fresh untransformed file by its original path, so OPcache caches it (~38 µs → ~10 µs per file, debug requests 27–40 % faster).
Production checklist
Section titled “Production checklist”-
Set
'debug' => falseand'features' => Features::PREBUILT_CACHE. -
Build the cache at deploy or image build time with
cache:warmup:aop. -
Keep
includePathsnarrow: yoursrc/, notvendor/. -
Register behavior classes with
addLazyService(). -
Install dependencies with
composer install --no-dev --classmap-authoritative. -
Run OPcache with
opcache.validate_timestamps=0and enough memory and file slots for the generated files. -
In containers, build the cache into the image, and add a primed
opcache.file_cacheor preloading.
The production kernel:
use Go\Aop\Features;
ApplicationAspectKernel::getInstance()->init([ 'debug' => false, 'appDir' => __DIR__ . '/..', 'cacheDir' => __DIR__ . '/../var/cache/aop', 'includePaths' => [__DIR__ . '/../src'], 'features' => Features::PREBUILT_CACHE,]);Building the cache at deploy time
Section titled “Building the cache at deploy time”rm -rf var/cache/aopvendor/bin/aspect cache:warmup:aop public/index.php --workers=$(nproc)Start from an empty directory, so the cache contains exactly the current release. The argument is the file that initializes your kernel: the front controller or a bootstrap file. The command executes it, so the kernel starts with the same options as in production.
The command:
- compiles every file below
includePaths(minusexcludePaths) and writes the generated files, the proxies, the behavior-class caches and both metadata files; - reports every file that cannot be compiled on stderr and exits with a non-zero code, so a deployment script or a
docker buildstops there instead of shipping an incomplete cache.
Rebuild the cache whenever the code, the behavior classes, the kernel options or composer.lock change. In practice that means on every deployment. Debug mode needs no rebuilds: it recompiles changed classes, behavior classes and kernel files by itself.
The full command signature:
cache:warmup:aop [<loader>] [--fail-fast] [--workers=N] [--cached-files=N] [--cache-dir=DIR] [--preload[=FILE]]Inside an application that has already initialized its kernel (the console of a framework integration), the loader argument is omitted and the command uses the kernel of the process. See Integrations.
Workers
Section titled “Workers”--workers=N compiles in N worker processes, largest files first. The default is 1, which compiles in the command process. Use the number of CPUs. The coordinator writes the metadata once, and every process keeps a bounded number of syntax trees in memory.
--cached-files=N sets that bound per process. It defaults to the parsedFilesLimit kernel option (100). More cached files mean fewer re-parses; fewer mean less memory. Add -v to list every file instead of the progress bar.
Building next to the running release
Section titled “Building next to the running release”--cache-dir=DIR builds the cache in another directory, from scratch, while the kernel keeps serving from its own. Use it to prepare the cache of the next release next to the running one and switch it in atomically, for example with a symlink swap.
A cache built this way is complete and location independent, also when a production kernel builds it while its own cache is warm. The compiler always reads the original sources of the classes it reflects, never the generated files that Composer serves in production.
Run over an existing directory, the command recompiles every file whose source changed (size or modification time) and keeps the others. This also holds with PREBUILT_CACHE: only requests trust the cache as it is, the warm-up command does not.
PREBUILT_CACHE and read-only file systems
Section titled “PREBUILT_CACHE and read-only file systems”Features::PREBUILT_CACHE makes requests trust the cache built at deploy time completely. It skips:
- the cache directory and writability probes;
- source
filemtimecomparisons; - tracked-resource checks;
- freshness checks of the behavior-class caches.
A request never compiles and never writes to the cache directory, so it works on read-only file systems. The cache must therefore be complete. A class or an included file below the include paths that the cache has no record of, or a record whose cached file is gone, fails the request with a WeavingException before anything is compiled. That includes a file added after the build, even one that needs no compiling.
Files the compiler never takes are loaded as they are: files outside the include paths, excluded files, and non-.php files such as an included template.
Every cache file is written to a unique temporary file, renamed into place and then invalidated in OPcache. Concurrent requests never see a half-written file, no locks are needed, and concurrent writers of the metadata merge their records.
Composer autoloader
Section titled “Composer autoloader”Classes that are not compiled are found by Composer as usual. With an optimized class map every lookup is an array access instead of a file_exists(), and the class map of the generated classes is merged into it with addClassMap(). Generated and untransformed classes are then served the same way.
Hot request of the benchmark:
| Autoloader | PREBUILT_CACHE |
debug => false |
Without the framework |
|---|---|---|---|
PSR-4 (composer install) |
5.5 ms | 6.7 ms | 2.3 ms |
--optimize-autoloader (-o) |
5.2 ms | 5.0 ms | 1.6 ms |
--classmap-authoritative (-a) |
4.8 ms | 4.6 ms | 1.9 ms |
With --classmap-authoritative Composer never looks for a class outside the class map. Run dump-autoload after any code generation and before the warm-up.
OPcache tuning
Section titled “OPcache tuning”Every compiled class becomes two cached files: its original body as a trait, and the proxy. Every behavior class gets a cache file of its own. Give OPcache room for them.
| Setting | Production value | Why |
|---|---|---|
opcache.enable |
1 |
Generated code is plain PHP, cached like the rest of the application. |
opcache.memory_consumption |
128–256 (MB) |
Check opcache_get_status()['memory_usage'] under load. |
opcache.interned_strings_buffer |
16–32 (MB) |
Proxies and generated traits share class and method names. |
opcache.max_accelerated_files |
≥ 2 × the PHP files of the application and vendor/ |
Every compiled class adds one file. |
opcache.validate_timestamps |
0 |
Immutable releases and containers: no stat per include. Reload PHP-FPM after a deployment. |
opcache.file_update_protection |
0 |
The framework writes every cache file atomically, so OPcache can cache freshly generated files immediately instead of waiting 2 seconds (the default). |
opcache.file_cache |
a directory | A second-level cache on disk: a new PHP-FPM master or CLI process loads compiled scripts instead of compiling them. Prime it at build time. |
opcache.preload |
optional | Links the generated classes once at server start, see Preloading. |
realpath_cache_size / realpath_cache_ttl |
4096K / 600 |
With validate_timestamps=1: fewer path lookups per include. |
Generated code is ordinary PHP, compiled by the JIT like the rest of the application. A typical web request spends its time in many short calls, where the JIT gains little, so measure before you enable it.
Preloading
Section titled “Preloading”Generated files are ordinary class declarations, so a prebuilt cache can be preloaded. --preload writes the opcache.preload script of the cache it builds: _preload.php in the cache directory, or the file given as --preload=FILE.
vendor/bin/aspect cache:warmup:aop public/index.php --workers=$(nproc) --preloadopcache.preload=/app/var/cache/aop/_preload.phpopcache.preload_user=www-dataThe bare --preload must come after the loader argument, otherwise it takes the loader as its value.
When PHP-FPM starts, the script requires Composer’s autoloader, hands it the class map of the generated classes and links into OPcache every compiled class, its proxy and every untransformed class known to the cache.
- Composer’s
filesautoloads (helper functions, polyfill bootstraps) are not preloaded. Requests include them as before. - The script holds no absolute path. Everything is located through
__DIR__, like the metadata files, so a cache moved together with the application stays valid. - It lists the classes of exactly the cache it was built with. Rebuild it with the cache.
- A class that cannot be linked while preloading (an optional dependency is missing) is written to the error log and left to the autoloader of the request.
- A class with a behavior on its static initialization is also left to the autoloader: the behavior needs the kernel, so the request loads it.
The kernel is still initialized on every request; the autoloader simply never has to load the preloaded classes. In the benchmark, preloading cut the included files per request from 517 to 174, the hot request from 5.2 ms to 4.9 ms, and the first request after a server start from 71 ms to 24 ms (10 ms together with a primed file cache).
Preloaded classes change only with a restart of PHP-FPM, which is how containers are deployed anyway. Nothing is preloaded in the CLI unless opcache.enable_cli=1 is set.
Docker and Kubernetes
Section titled “Docker and Kubernetes”Build the framework’s cache into the image. Every container then starts with a complete, read-only cache, every replica serves exactly the same generated code, and no pod ever compiles. The shop demo ships this setup as a working image.
Dockerfile
Section titled “Dockerfile”FROM php:8.5-fpm
# OPcache is part of PHP 8.5, no docker-php-ext-install neededCOPY docker/opcache.ini /usr/local/etc/php/conf.d/opcache.iniCOPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /appCOPY composer.json composer.lock ./RUN composer install --no-dev --no-scripts --no-autoloader --prefer-distCOPY . .RUN composer dump-autoload --no-dev --classmap-authoritative
# 1. The framework's cache: generated classes, proxies, behavior caches, metadata, owned by the user that serves it# (cache files get the `cacheFileMode` kernel option, by default 0770 minus the umask)RUN rm -rf var/cache/aop \ && php vendor/bin/aspect cache:warmup:aop public/index.php --workers="$(nproc)" --preload \ && chown -R www-data:www-data var/cache/aop \ && chmod -R a-w var/cache/aop
# 2. The OPcache file cache: a new PHP-FPM master loads compiled scripts instead of compiling them.# Built in the final image, as the file cache belongs to this PHP build and these paths.RUN mkdir -p /var/cache/opcache \ && php -d opcache.enable_cli=1 -d opcache.file_cache_only=1 -d opcache.file_cache=/var/cache/opcache \ vendor/bin/aspect cache:warmup:opcache public/index.php --file-cache=/var/cache/opcache --entry=public/index.php \ && chown -R www-data /var/cache/opcache
USER www-datacache:warmup:opcache compiles what the application loads: the framework’s cache (generated files, proxies, behavior-class caches and metadata), Composer’s class map and autoloaded files, the sources below the include paths that are not compiled, the loader file, and the entry points given with --entry.
- Compiled scripts are written to disk only by a process started with
opcache.enable_cli=1,opcache.file_cache_only=1andopcache.file_cache=DIR. These cannot be set at runtime. The command checks them, and that--file-cache=DIRis the configured directory, and prints the exact command to run otherwise. - The framework’s cache, the loader and the entry points must compile, or the command fails. A file of the Composer class map that does not compile (a vendor test stub written for a newer PHP) is listed and skipped; PHP logs the compile error.
- Run it after
cache:warmup:aop, in the final image, with the PHP binary that serves the requests. The file cache is keyed by the PHP build and the absolute paths of the files.
opcache.ini
Section titled “opcache.ini”opcache.enable=1opcache.memory_consumption=192opcache.interned_strings_buffer=32opcache.max_accelerated_files=50000opcache.validate_timestamps=0opcache.file_cache=/var/cache/opcacheopcache.file_cache_consistency_checks=0; PHP 8.5: the primed file cache is only read at runtime, also on a read-only root file systemopcache.file_cache_read_only=1; required on PHP 8.5.11 / 8.5.12, see "JIT"opcache.jit=disable; optional, see "Preloading" (written by cache:warmup:aop --preload); opcache.preload=/app/var/cache/aop/_preload.php; opcache.preload_user=www-dataThe kernel of the image is the production kernel from the checklist: debug => false, includePaths limited to src/, and Features::PREBUILT_CACHE.
In the benchmark this setup serves the first request of a fresh server in 19 ms with the file cache, and in 10 ms with the file cache plus preloading, against 71 ms without either. Pods are fast from their first request.
Kubernetes
Section titled “Kubernetes”- Read-only root file system (
readOnlyRootFilesystem: true).PREBUILT_CACHEreads the cache built into the image and writes nothing at runtime. - One image, one cache. Keep the cache inside the image rather than on a shared volume, so every release serves exactly the code it was built from.
- Rolling updates need nothing special. New pods bring their own cache, old pods keep theirs.
- When the image cannot contain the cache, run
cache:warmup:aopin an init container that writes to anemptyDirvolume mounted at the cache path of the application container. This keepsPREBUILT_CACHE, and the pod becomes ready with a complete cache. - CLI containers (queue consumers, cron jobs) use the same image and cache. Enable
opcache.enable_cli=1together with the primedopcache.file_cache, see CLI processes.
Long-running workers
Section titled “Long-running workers”Long-running workers (RoadRunner, FrankenPHP worker mode, Swoole, ReactPHP) boot the kernel once per worker. The call contexts stay initialized from one request to the next.
Writing fast behaviors
Section titled “Writing fast behaviors”- Target precisely. Only matched members are intercepted and only matched classes are compiled, so a precise rule is a fast one.
execution(public App\Service\*->*(*))also matches constructors. Add&& !execution(**->__construct(*))when you do not need them. - Prefer method rules to
initialization(...). While aninitializationrule is registered, everynewin the generated files goes through the transformer. A class without initialization behaviors (and with a public constructor) is still created by a nativenew, which costs roughly 130 ns more than a plainnew. A class with initialization behaviors goes through the full call context. - Register behavior classes lazily with
addLazyService(). The behavior class and its dependencies are created on the first behavior call, not on every request. - Keep behaviors cheap.
getMethod()andgetField()create a reflection object on first use per call context. Derive attributes or names from it once and keep them in the behavior class, keyed byclass::method. - Format call contexts lazily.
(string) $invocationbuilds a string on every call. Use it only for messages that are actually written. - Native includes.
Features::INTERCEPT_INCLUDESroutesinclude/requirein generated files through the compiler, for legacy code that is not loaded by Composer. With it, anincludeof a file known to the cache is served by its original or cached path in production, without the stream filter (~250 µs → ~11 µs per include).
A lazily registered behavior class:
use Go\Core\AspectContainer;use Go\Core\AspectKernel;use Psr\Log\LoggerInterface;
class ApplicationAspectKernel extends AspectKernel{ protected function configureAop(AspectContainer $container): void { // Runs when one of its behaviors first runs, after the application container is attached $container->addLazyService( MonitorAspect::class, static fn(AspectContainer $container) => new MonitorAspect($container->getService(LoggerInterface::class)), ); }}Writing behaviors and matching rules is covered in Behaviors & Matching Rules.
Troubleshooting
Section titled “Troubleshooting”Warm-up and prebuilt cache
Section titled “Warm-up and prebuilt cache”| Message or symptom | Meaning and what to do |
|---|---|
cache:warmup:aop writes errors to stderr and exits with a non-zero code |
A file cannot be compiled. The deploy or docker build stops so that an incomplete cache is never shipped. Fix the file and run the warm-up again. |
WeavingException: ... is missing from the prebuilt AOP cache in ... |
With PREBUILT_CACHE, a class or included file below the include paths has no record in the cache, or its cached file is gone. Rebuild the cache with cache:warmup:aop. |
cache:warmup:opcache prints a command instead of priming the cache |
The process was not started with -d opcache.enable_cli=1 -d opcache.file_cache_only=1 -d opcache.file_cache=DIR, or --file-cache names another directory. Run the printed command. |
Preloading errors
Section titled “Preloading errors”PHP reports preloading problems once, when the PHP-FPM master (or php -S) starts, in its error log.
| Message | Meaning and what to do |
|---|---|
Fatal Error "opcache.preload" requires "opcache.preload_user" when running under uid 0 |
The master runs as root. Set opcache.preload_user to the user the workers run as (www-data). |
Failed opening required '.../_preload.php' |
The script is missing: the cache was built without --preload, or opcache.preload points at another cache directory. Rebuild with cache:warmup:aop --preload. |
Go! AOP preload: <class> is left to the autoloader: ... |
The script could not load a class of the cache, mostly because an optional dependency is not installed (a --no-dev image). Harmless: the class is not preloaded, and a request that needs it autoloads it as usual. |
Can't preload unlinked class <class>: Unknown parent/trait/interface <name> in <file> |
OPcache could not link a class of a file the preload included, for the same reason. It comes together with the line above for a class of the cache. Harmless: the class is simply not preloaded. |
Can't preload unlinked class class@anonymous: Unknown trait ... in a vendor helper file |
An anonymous class of a Composer files autoload, for example Laravel’s Illuminate/Reflection/helpers.php. The script of the cache leaves these files out; the warning comes from another script that requires vendor/autoload.php before it. Require the script of the cache first: Composer then returns its loader without including the files again. |
Reproducing the benchmarks
Section titled “Reproducing the benchmarks”The application, the benchmark scripts and the Docker image are in goaop/shop-demo. One script reproduces every table on this page:
bash bench/run-all.shHow the numbers were measured
Section titled “How the numbers were measured”- Application: ~45 hand-written classes (domain, repositories, services, controllers, in-memory infrastructure), 40 generated modules (service and repository compiled; DTO, validator and event not compiled) and 120 library classes outside the include paths.
- Behavior classes: logging (
#[Before]on an attribute), caching and transactions (#[Around]on attributes), monitoring (#[Around]on repositories,#[AfterThrowing]on services), stock audit (#[Around]on a property), security (#[Before]on module services). - Baseline: the same code without the kernel. Its behaviors do not run.
- Runtime: PHP 8.5.12 NTS, 4 CPUs, OPcache with
opcache.jit=disableandopcache.file_update_protection=0. - Web requests: the built-in web server (
php -S, one worker, OPcache shared memory kept between requests). Warm is the first request of a freshly started server (7 samples); hot is the median of 350 requests. Times are measured inside the script withhrtime(). - Profiles: Xdebug 3.5
xdebug.mode=profileruns of every mode and state, used for call counts and the distribution of the time. The times come from runs without Xdebug.
The ratios between the modes are what carries over to other machines.
© 2026 Alexander Lisachenko
