The shared test application of orisai/phpstan-nette and
orisai/phpstan-spaghetti: a generated Nette application with legacy
include scripts, used to measure how long PHPStan takes on it with given versions of the libraries, where that time
goes, and whether a library change altered the findings (the snapshot in expected/).
The application is generated by tools/generate.php and checked in, so every checkout measures the same code. It is
shaped like the libraries' reference consumer (its proportions, not its code).
- The application
- Installation
- Running
- Reading the output
- Measuring other versions of the libraries
- Findings snapshot
- When the findings change
- CI
- Profiling
- Caveats
- Reference numbers
Generated at 120 200 60 120 2000 (presenters, form controls, grids, scripts, models): 3,002 PHP files in app/,
lib/ and scripts/ and 642 Latte templates.
| part | files | what it is | what it makes the libraries do |
|---|---|---|---|
| presenters | 121 PHP, 361 templates | 120 presenters over a BasePresenter, each with five factories (a grid from a generated factory with an onReload closure, two form controls from generated factories, a search form built locally through a helper, a menu), two or three signal handlers, actions and renders with typed template values, a layout and three templates with {form}, {input}, {control} and snippets |
the component tree trace (one per child path), the Latte render-path trace over the whole lifecycle, template variables, the latte-component bridge |
| form controls | 405 PHP, 200 templates | 200 controls over 5 abstract base builders, one pattern per base: a hook with a method handler; two hooks with a closure handler; a container with onValidate; setDefaults with an onError closure; a replicator with a row closure and onClick |
the forms trace and the old forms engine: shapes through template methods, hooks, containers, replicators, handlers and their value types; {form}/{input} pairing in templates |
| cooperation controls | 41 PHP, 20 templates | BaseCooperationControl, an abstract control whose form comes from a FormFactory service in a private property, built with containers and an abstract hook; 20 final Coop*Controls adding their fields in the hook, each rendered by its own template |
a form of a factory service through a private property, hooks across an abstract base, the template pairing of a subclass |
| form classes | 6 PHP | AppForm, AppContainer, AppReplicator (kdyby/forms-replicator) and AppSubmitButton, with a first-party trait overriding addContainer, addEmail, addDynamic, addSubmit and setDisabled (the consumer's ContainerSharedMethods pattern), FormFactory |
first-party add-methods with @form-adds, the replicator chain in vendor code, defaultContainerClass |
| helpers | 20 PHP | static and instance helpers adding fields, containers and replicators to a form they are given | interprocedural adds: every helper body is traced once per calling form |
| grids | 121 PHP, 60 templates | 60 grids over a BaseGrid with an event, signals and a filter form |
events and their handlers, signals, a filter form no template of the presenter pairs |
| data grids | 30 PHP, 2 in lib/ |
lib/datagrid, a vendor-like data grid (scanned, not analysed) building its inner form in branches and loops, and 30 DataGrid*Controls registering twelve columns each with closures |
the traces running vendor code: a form built outside the analysed paths |
| legacy scripts | 120 PHP | file-level scripts, two thirds of them building a form; each takes its repository from the container of scripts/bootstrap.php (require_once) and includes scripts/layout/header.php (a header contract: @var string $title, @var Container $container) and footer.php |
forms outside classes, the outside-adds index; for spaghetti: 120 sites of one header, a bootstrap followed through require_once, variables forwarded to the footer |
| service scripts | 30 PHP, 60 in app/Control/Scripts |
scripts reading a form an Edit*Control builds, the control from its generated factory, taken from the container of the bootstrap |
a form of a factory service across the bootstrap include, the forms trace in scripts |
| include scenarios | 26 PHP | scripts/includes/ and scripts/layout/: a handful of scripts for every finding of the include rules (see below) |
each spaghetti rule firing a few times |
| forms across includes | 17 PHP | scripts/forms/: the scenarios orisai/phpstan-spaghetti pins with orisai/phpstan-nette (a form built in one file and read, extended, conditionally included, included once, inside a function, from a service, shared by two includers, next to an unrelated include), with dumpType() putting the answers into the findings |
the two libraries together |
| models | 2,000 PHP | 1,000 repositories and 1,000 entities with 25 methods each | plain PHPStan work: about 40 % of a first run |
| DI container | config/services.neon, container-loader.php |
a compiled nette/di container: presenter mapping, inject: true presenters, generated factories, Latte |
the DI extension, injections, the template factory loader |
The include scenarios, a fixed number whatever the size (the legacy scripts carry the volume):
| finding | scripts |
|---|---|
orisai.spaghetti.includedVariableType |
includes/typed{0,1,2}.php pass an int, null and an array as $title |
orisai.spaghetti.includedVariablePossiblyUndefined |
includes/maybe{0,1,2}.php define $title in a branch |
orisai.spaghetti.includedVariableUndefined |
includes/untitled{0,1}.php do not define $title |
orisai.spaghetti.headerVariableUnused |
layout/box{0,1,2}.php declare a variable they never read |
orisai.spaghetti.headerVariableAssignType |
layout/counter{0,1}.php assign their int $count a string and null |
orisai.spaghetti.includeNotDiscoverable |
includes/router.php includes from request data and $_SERVER |
orisai.spaghetti.includedFileNotFound, includedFilePossiblyNotFound |
includes/stale.php |
orisai.spaghetti.includeCycle |
includes/cycle/ (plain includes); includes/once/ is the same cycle through require_once, which is no cycle and reports nothing |
tools/generate.php is deterministic: two generations give byte-identical trees. It follows the profiling generator of
orisai/phpstan-nette (tools/profiling/generate.php, ported at 31ff0ca) with a static PHPStan configuration, the
argument checks and the removal of the earlier output kept here, and adds the legacy layout, the include scenarios and
the forms across includes.
php8.4 tools/generate.php <out dir> [presenters=120] [formControls=200] [grids=60] [scripts=120] [models=2000]It writes <out>/app, <out>/lib, <out>/scripts, <out>/config/services.neon and <out>/container-loader.php
and deletes whatever was there before. Form controls must be at least 5 (one per base builder) and models at least 2
(half repositories, half entities); presenters reuse grids and form controls round-robin. The cooperation controls are
a tenth of the form controls, the data grids half the grids, the service scripts a quarter of the scripts (each at
least 2).
make generateregenerates the checked-in application in place,make generate OUT=<dir> SIZE="10 15 5 10 100"writes another size into a scratch directory (never check one in).make check-generatedfails when the checked-in application differs from a fresh generation. Run it after changing the generator, thenmake generate,make findingsand check in the result together with the updatedexpected/.
make bench and make profile analyse another application with APP=<dir> (see Running).
The generated code parses on PHP 7.4, the oldest PHP the libraries support; it is analysed with phpVersion: 80400
(see Caveats).
Requires Linux (x86_64 or arm64; PHPStan's turbo extension is loaded from vendor/phpstan/phpstan/turbo-ext/linux-gnu-*),
PHP 8.4 with the pcntl and posix extensions (for the profiler), GNU time at /usr/bin/time, and shellcheck for
make shellcheck.
make install # php8.4 composer installBoth libraries come from Packagist as 1.x-dev (their v1.x branches; Packagist names the version v1.x-dev).
composer.lock pins the commits the snapshot was taken at; composer update orisai/phpstan-nette orisai/phpstan-spaghetti moves them to the newest pushed commits.
The libraries' primary development dependency set is installed: nette/application and nette/forms 3.3.1, nette/di
3.2.8, nette/component-model 4.0.2, nette/utils 4.1.6, nette/neon 3.4.10, latte/latte 3.1.10, kdyby/forms-replicator
3.0.1, phpstan/phpstan 2.3.7, with phpstan/phpstan-nette 2.0.15 (patched like in orisai/phpstan-nette, so its
component-model and form-values return types can be switched off), phpstan-strict-rules and
phpstan-deprecation-rules next to the libraries, as the reference consumer runs them. shipmonk/dead-code-detector is
not installed: its findings on the generated models would bury the rest of the snapshot, so the libraries'
dead-code configurations (config/dead-code.neon, config/dic-dead-code.neon) are not included either.
| target | what it does |
|---|---|
make bench |
first, cold and warm runs, each N times, with PROCESSES parallel processes |
make bench-debug |
first and cold runs, each N times, in one process with --debug |
make compare A=<variant> B=<variant> |
the runs of make bench for two variants, interleaved A, B, A, B |
make findings |
the sorted findings of a first run, written to expected/ |
make check-findings |
the findings of a first run written to var/findings/, then a diff against expected/ (also in var/findings.diff) |
make profile |
one sampled first (or KIND=cold) run in one process and its attribution by domain |
make generate, make check-generated |
see Generating |
make shellcheck |
checks the shell scripts |
make clean |
deletes var/ |
| variable | default | used by |
|---|---|---|
N |
3 | runs of each kind per variant |
PROCESSES |
8 | PHPStan's parallel.maximumNumberOfProcesses (bench, compare, findings) |
KINDS |
first cold warm (first cold for bench-debug) |
which kinds of run, in this order |
LIB |
(the installed libraries) | library checkouts to measure instead, see below (bench, bench-debug, findings, check-findings, profile) |
KIND |
first |
profile: first or cold |
SAMPLER_US |
2000 | profile: the sampling interval in microseconds |
APP |
this repository | the application's root, as written by tools/generate.php |
PHP |
php8.4 |
the PHP binary |
The kinds of run:
- first: empty stores; the whole PHPStan tmpDir of the variant is deleted before the run. What a developer sees after a library update or on CI without a cache.
- cold: PHPStan's result cache deleted, the libraries' stores and PHPStan's other caches kept. Every file is analysed again, the libraries answer from their stores. The first cold run after a first run still computes the answers a first run could not store (the one-run lag), so cold #1 after first runs is usually slower than the others.
- warm: everything kept, nothing changed: PHPStan restores its result cache.
Every kind runs N times before the next kind starts; with several variants, each run of A is followed by the same
run of B. --debug never uses the result cache, so make bench-debug has no warm run.
PHP is started the way PHPStan's own restart would start it (OPcache, the turbo extension, no JIT, no pcov),
with zend.assertions=-1 and PHPSTAN_RESTART=manual, so the result does not depend on php.ini. PHPStan changes its
output when it detects an AI agent (CLAUDECODE, AI_AGENT and others in its AgentDetector); the scripts unset
those variables, so a run gives the same output for a human, an agent and CI. The configuration of every run is
written to var/conf/, its output to var/bench/ (.out the raw findings, .err PHPStan's stderr, .usage the
resource usage).
variant vendor: phpstan-nette /…/vendor/orisai/phpstan-nette, phpstan-spaghetti /…/vendor/orisai/phpstan-spaghetti
application /…/phpstan-ext-bench, 8 processes, 32 CPUs, php8.4
kind run variant wall s user s sys s peak MB findings load1
first 1 vendor 77.11 365.34 15.90 1095 3773 13.24
wall s: elapsed time of the run.user s,sys s: CPU time of PHPStan and all its workers. With parallel runs, user time is the better measure of work done and is less sensitive to load than wall time.peak MB: the maximum resident set size of the largest single process (the coordinator or one worker), not the sum.findings: the number of findings reported. It must be the same for every run of a variant; if not, a store answers differently than a computation.load1: the 1-minute load average when the run started. Compare runs only at similar load, see Caveats.
The tools print numbers and judge none of them.
LIB=<dir>[,<dir>] measures library checkouts instead of the installed libraries, without touching vendor/. Each
directory is a checkout of orisai/phpstan-nette or of orisai/phpstan-spaghetti, told apart by its extension.neon;
the library not named stays the installed one. The configuration includes <dir>/extension.neon instead of the
installed one, and tools/autoload.php (PHPStan's --autoload-file, loaded in every process before the container is
built) points the Composer autoloader's OriPhpstan\Nette\ or OriPhpstan\Spaghetti\ prefix at <dir>/src.
Everything else comes from vendor/, so the version must work with the installed dependencies. The same values are
the variants of make compare (vendor for the installed libraries).
A commit is extracted with git archive, which leaves out the libraries' tests and tools:
mkdir -p /tmp/nette-abc1234 && git -C ../phpstan-nette archive abc1234 | tar -x -C /tmp/nette-abc1234
mkdir -p /tmp/spaghetti-def5678 && git -C ../phpstan-spaghetti archive def5678 | tar -x -C /tmp/spaghetti-def5678
make compare A=/tmp/nette-abc1234 B=../phpstan-nette
make check-findings LIB=/tmp/spaghetti-def5678
make check-findings LIB=/tmp/nette-abc1234,/tmp/spaghetti-def5678A working tree (LIB=../phpstan-nette) is measured as it is, uncommitted changes included. Each variant has its own
PHPStan tmpDir, var/tmp/<name>-<hash of its path>[+…] (var/tmp/vendor for the installed libraries), so stores
never mix. Do not optimise the Composer autoloader (-o, --classmap-authoritative): a class map would load the
installed libraries' classes.
For A/B comparisons, prefer two extracted directories over the installed library against an extracted one: the paths and file systems are then alike.
expected/ holds the findings of the application at orisai/phpstan-nette 4d73498ceede48c07e99860ca3a22701f41243a5
(4d73498) and orisai/phpstan-spaghetti bd2ede534560e5f6453c09794218bac9e8812f44 (bd2ede5): 3,896 findings, one per
line, sorted, paths relative to the application, a message spanning lines joined with a literal \n, the identifier
in brackets. They are split by part (tools/findings.php), so a diff shows which part a change touched:
| file | findings | what |
|---|---|---|
expected/spaghetti.txt |
560 | everything in scripts/ and every orisai.spaghetti.* finding: the include rules, the forms across includes (dumpType()), the forms in legacy and service scripts |
expected/latte.txt |
1,830 | everything in Latte templates |
expected/nette.txt |
181 | the other orisai.nette.* findings (forms, components) |
expected/phpstan.txt |
1,325 | the rest: PHPStan's own and its other extensions' findings in app/, which the libraries' type answers feed |
make check-findings analyses from empty stores and diffs against expected/, a cheap differential check that a
library change did not alter the answers on this application.
The Library updated workflow installs the newest 1.x-dev of both
libraries and runs make check-findings. It runs every day, by hand, and when a library's CI sends a
repository_dispatch of type library-updated. When the findings differ it fails, prints the diff, puts it in the job
summary and uploads it with the new findings and composer.lock as an artifact: a library change altered the answers
on the shared application. The library's maintainer then:
- if the change is intended: in this repository,
composer update orisai/phpstan-nette orisai/phpstan-spaghetti,make findings, reviewgit diff expected/(it must be the same as the workflow's diff), and commitcomposer.lockandexpected/together, naming the library commit in the message ("Findings of orisai/phpstan-nette abc1234: …"), then update the commits named in Findings snapshot; - if it is not: fix the library. The diff names the files and lines of this application to reproduce it with
(
make check-findings LIB=<checkout>).
A library's own CI triggers the workflow after a push to v1.x with a step like this one, which needs a secret
holding a token allowed to dispatch to this repository (a fine-grained personal access token with access to
orisai/phpstan-ext-bench only and the "Contents: read and write" repository permission, or a GitHub App token):
- name: "Shared application"
if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/v1.x' }}"
env:
GH_TOKEN: "${{ secrets.EXT_BENCH_DISPATCH_TOKEN }}"
run: >-
gh api repos/orisai/phpstan-ext-bench/dispatches
-f event_type=library-updated
-F "client_payload[repository]=${{ github.repository }}"
-F "client_payload[sha]=${{ github.sha }}"Packagist needs some tens of seconds to see the push, so the step belongs at the end of the library's CI (after its tests), not at its start.
| workflow | when | what |
|---|---|---|
| CI | push, pull request | composer install (the locked libraries), make check-generated, make check-findings, make shellcheck |
| Library updated | daily, by hand, repository_dispatch library-updated |
the newest libraries against expected/, see above |
| Benchmark | by hand | make bench N=<runs> with as many processes as the runner has CPUs, the table in the job summary |
GitHub's runners are shared virtual machines: the benchmark there is indicative only, never a baseline to compare
another run against. Compare versions with make compare on one machine.
make profile runs one analysis in one process (--debug) with a sampling profiler and prints the attribution of
its time by domain. The full report goes to var/profile/profile-<variant>-<kind>.txt.
tools/profile/sampler.php, loaded throughtools/autoload.phpwhenSAMPLER_OUTis set: a forked child sends SIGPROF everySAMPLER_USmicroseconds and the handler takesdebug_backtrace(). Each sample records the innermost and outermost domain marker class (a namespace of orisai/phpstan-nette,spaghettifor orisai/phpstan-spaghetti,phpstanwhen no library frame is on the stack), the innermost library frame, the leaf outside the library, whether the tracing core'sComposeris on the stack and the kind of file being analysed (set bytools/profile/SamplerFileRule.php).tools/profile/report.php <json>...sums one or more sampler outputs and prints the tables: by domain, by outermost domain (who asked first), by trace domain, by leaf, by file kind, and the top functions.tools/profile/store-stats.php <tmpDir>andtools/profile/store-detail.php <tmpDir>summarise orisai/phpstan-nette's stores after a run (var/tmp/<variant>): kinds, sizes, dependency counts, the files answers depend on.
The sampler's limits:
- The two Latte rule decorators are transparent unless they are the leaf; otherwise every PHPStan rule's time would count as Latte.
- Samples taken while a
.lattefile is analysed are counted (latte-file) but not unwound: unwinding there crashed PHP 8.4 twice with the same NULL dereference in the engine.SAMPLER_LATTE=1unwinds them anyway. - Interrupt skid inflates tiny per-expression extensions. Domain totals are robust; single leaf functions at a PHPStan to library boundary are not.
- The domains are regular expressions over the libraries' namespaces in
Sampler::classify(); a class moved to another namespace changes domain until they are updated.
Counters inside the library (trace and memoisation counts, region timing) are kept with the library itself, in
orisai/phpstan-nette's tools/profiling/, as a patch for its current code; when one is applied in a checkout, the
sampler also attributes samples to traced bodies.
- The application is forms- and factory-heavier than the reference consumer (about 340 controls against 150,
310 generated factories and 518
createComponent*()methods against 304 factories). Its forms and trace shares probably overstate the consumer's. The consumer's answers reach more vendor files (data grids and others) than the one generated data grid. phpVersionis 80400, the consumer's is 70400. With 70400 PHPStan cannot reflect the installed nette 3.3 (Nette\Forms\Containerbecomes unknown); the consumer runs nette 3.1. The generated code parses on PHP 7.4.- Load sensitivity. Wall times move with the machine's load; parallel runs more than single-process ones. Compare
only runs made at similar load, interleaved (
make compare), and prefer CPU time to wall time. - Ratios over absolutes. Absolute times hold for one machine at one load. A change is better judged by the ratio
between versions in the same
make compare, and by counts (findings, stores) that do not depend on the machine. - The configuration follows the consumer's PHPStan configuration without its application-specific parts and without the dead-code detector.
make bench N=1 with the installed libraries at 31ff0ca and 3823db8, on 2026-11-28: a 32-CPU WSL2 machine, PHP
8.4.27, 8 processes. About ten other agents' test suites ran on the machine at the same time; the 1-minute load was
between 13 and 30 (see the last column), so these are an order of magnitude, not a baseline to compare a new run
against. Measure both versions in one make compare instead.
| kind | run | wall s | user s | sys s | peak MB | findings | load1 |
|---|---|---|---|---|---|---|---|
| first | 1 | 77.11 | 365.34 | 15.90 | 1095 | 3773 | 13.24 |
| cold | 1 | 28.48 | 187.90 | 5.49 | 637 | 3773 | 28.83 |
| warm | 1 | 3.85 | 3.43 | 0.40 | 431 | 3773 | 29.81 |