Skip to content

Perf: record usage-inferred param types only for methods in the project directories (one thread: -8 to -15 % wall on apps that analyse their tests) - #13901

Merged
alies-dev merged 7 commits into
vimeo:masterfrom
alies-dev:perf-usage-param-types
Nov 22, 2026

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

When a full run infers param types from usage (it does so to count MissingParamType and, under --alter, to fix it), every call to a method with an untyped or native mixed param adds the argument's type to a union kept per method in Analyzer::$possible_method_param_types. The only reader, ClassLikes::findPossibleMethodParamTypes(), uses it only for methods of non-trait classes in the project directories whose file is reportable. Calls to vendor methods are recorded anyway and never read. Test suites pay the most: PHPUnit's assertSame(mixed $expected, mixed $actual) ends up with a union of every value any test asserted, and every further call combines into it.

Now a method's calls are recorded only if it has a location and its declaring class is not a trait and lies in the project directories, which the config fixes for the whole run. Recording doesn't check whether the file is reportable: plugin hooks can change that during the run (addFilesToAnalyze(), addFilesToShowResults(), Codebase::addReportableFiles()), and the reader checks it at the end anyway. Recording also stops combining an entry once it is a plain mixed, since the reader then skips that param whatever else is passed.

Benchmarks

Apple M1 Pro (10 cores, 32 GB), PHP 8.5.12, igbinary 3.2.17RC1, master 0fd455b against this branch. --no-cache unless the mode says warm (a cache filled by an uncounted cold run of the same version). Runs of the two versions alternate. Peak is the main process's memory_get_peak_usage(). A change is marked only where the medians differ by more than 2 % (3 % for wall and analysis, 1 % for peak) and by more than the spread of the cell's runs. Taint is on for the big Laravel project, laravel/framework, WordPress, PHPUnit, Composer and Bagisto.

The gain depends on whether the project directories include tests that pass many values to untyped or mixed params. The big Laravel project, doctrine/orm, PHPUnit and Composer analyse their tests; the other seven apps analyse only their sources.

One thread (2 runs per cell)

This is where the change shows: one process collects the argument types of every call, so the unions grow largest.

project wall s, master wall s, branch CPU s, master CPU s, branch analysis s, master analysis s, branch peak MB, master peak MB, branch
big private Laravel project 253.2, 238.7 211.7, 204.7 (-15 %) 234.2, 236.9 205.0, 204.4 (-13 %) 203.5, 191.3 157.2, 157.5 (-20 %) 7 517 7 508
phpunit 25.9, 25.6 22.2, 22.1 (-14 %) 25.6, 25.6 22.1, 22.0 (-14 %) 20.2, 20.3 16.9, 16.8 (-17 %) 1 290 1 286
doctrine/orm 25.4, 25.1 23.3, 23.4 (-8 %) 25.1, 25.0 23.1, 23.3 (-7 %) 19.0, 19.0 17.2, 17.2 (-9 %) 1 143 1 138
composer 17.7, 17.4 17.4, 17.4 17.5, 17.3 17.4, 17.4 12.1, 12.1 12.1, 12.1 698 698
laravel/framework 53.8, 52.9 53.0, 52.9 53.1, 52.9 52.9, 52.9 40.9, 40.9 41.0, 41.0 1 735 1 734
mediawiki 118.1, 116.8 119.7, 117.3 117.5, 116.7 119.6, 117.2 102.3, 101.8 104.4, 101.9 2 106 2 106
symfony (no taint) 76.0, 75.3 75.1, 75.1 75.2, 75.2 75.0, 75.0 56.3, 56.6 56.3, 56.4 3 326 3 326
drupal 60.9, 60.0 59.9, 60.0 60.1, 59.8 59.8, 59.8 47.1, 47.1 47.1, 47.1 1 985 1 984
wordpress 89.2, 88.4 88.3, 88.4 88.2, 88.2 88.1, 88.3 77.9, 77.9 77.8, 78.0 2 036 2 036
nextcloud 63.7, 62.5 62.5, 62.4 62.9, 62.5 62.5, 62.4 41.1, 41.0 41.1, 40.9 3 862 3 862
bagisto 37.1, 36.1 36.0, 36.1 36.3, 36.1 36.0, 36.1 20.8, 20.9 20.8, 20.8 1 845 1 845

At the end of the analysis master holds these unions at 4.5 MB (igbinary size) on the big Laravel project, the branch 83 KB; phpunit 2.6 MB against 78 KB, doctrine/orm 1.5 MB against 110 KB. Composer's tests pass almost nothing to such params (12 KB on master), so it gains nothing. The scan phase is unchanged everywhere.

Eight threads (3 runs per cell)

Each worker collects only its own files' calls, so the unions stay small and the change is mostly within noise.

project wall s, master wall s, branch CPU s, master CPU s, branch analysis s, master analysis s, branch peak MB, master peak MB, branch
big private Laravel project 82.0, 80.0, 79.9 79.2, 79.7, 79.2 312.1, 310.6, 309.8 302.7, 302.9, 303.5 (-2 %) 29.4, 28.8, 28.7 28.3, 28.7, 28.3 7 180 7 160
phpunit 11.0, 10.7, 10.3 10.5, 9.4, 10.2 31.0, 30.8, 30.1 30.3, 29.2, 29.7 5.5, 5.6, 5.5 5.5, 4.4, 5.5 1 080 1 068 (-1 %)
doctrine/orm 8.6, 8.2, 8.2 8.1, 8.1, 8.1 31.1, 30.9, 31.0 30.5, 30.3, 30.4 3.1, 3.2, 3.1 3.1, 3.0, 3.1 807 798 (-1 %)
composer 7.1, 6.9, 7.0 6.8, 7.0, 6.9 22.0, 22.1, 22.2 22.0, 22.2, 22.1 2.2, 2.2, 2.2 2.2, 2.2, 2.2 451 451
laravel/framework 28.7, 28.0, 28.0 28.0, 28.0, 28.0 62.9, 62.6, 62.5 62.6, 62.6, 62.7 16.4, 16.4, 16.4 16.4, 16.4, 16.3 1 616 1 615
mediawiki 26.6, 25.5, 25.5 25.3, 25.3, 25.6 148.2, 143.1, 143.1 143.1, 143.1, 143.2 16.6, 16.0, 15.9 15.9, 15.9, 16.0 1 203 1 203
symfony (no taint) 19.0, 18.5, 18.5 18.7, 18.8, 18.5 102.9, 102.1, 101.8 102.6, 102.4, 101.7 10.3, 10.4, 10.5 10.5, 10.5, 10.4 995 994
drupal 17.8, 17.4, 17.6 17.3, 17.5, 17.7 80.1, 79.4, 79.4 79.4, 79.5, 79.1 8.2, 8.1, 8.1 8.1, 8.1, 8.1 1 299 1 298
wordpress 20.6, 19.7, 20.4 20.3, 19.8, 20.4 108.3, 107.4, 107.5 108.9, 107.6, 107.7 12.6, 12.4, 12.4 12.5, 12.4, 12.4 1 283 1 282
nextcloud 16.5, 15.7, 15.6 15.7, 15.7, 15.6 82.3, 82.1, 82.9 81.5, 82.2, 83.3 7.4, 7.1, 7.2 7.1, 7.2, 7.1 1 172 1 171
bagisto 19.8, 19.8, 19.9 19.2, 19.9, 19.4 52.1, 53.1, 53.1 52.3, 53.4, 52.4 4.2, 4.3, 4.3 4.2, 4.3, 4.2 1 739 1 738

On the big Laravel project the workers ship 5.15 MB of these unions on master and 0.11 MB on the branch; its merge phase is 3.8 s against 3.6 s. An earlier block of the same runs, while Spotlight was indexing on the machine, gave phpunit 10.3 → 9.2 s wall (analysis 5.6 → 4.4 s) and the big Laravel project the same -2 % CPU.

Eight threads, warm cache (4 runs per cell)

project wall s, master wall s, branch CPU s, master CPU s, branch analysis s, master analysis s, branch peak MB, master peak MB, branch
big private Laravel project 58.6, 58.3, 57.4, 57.7 57.3, 57.7, 56.7, 56.1 233.8, 235.2, 234.9, 235.2 230.2, 230.4, 233.0, 230.3 26.6, 26.6, 26.5, 26.8 26.2, 26.1, 26.1, 25.7 6 230 6 211
laravel/framework 24.2, 24.0, 24.1, 23.9 24.0, 24.0, 24.2, 24.4 54.9, 54.8, 54.7, 54.6 54.8, 54.7, 54.9, 54.4 16.2, 16.1, 16.2, 16.1 16.1, 16.1, 16.2, 16.1 1 731 1 730
mediawiki 20.1, 20.0, 19.8, 20.1 19.8, 19.9, 20.3, 20.0 123.0, 122.6, 122.3, 123.0 122.3, 122.6, 123.2, 123.1 15.0, 14.9, 14.8, 15.0 14.8, 14.9, 15.0, 15.0 1 199 1 198
symfony (no taint) 14.6, 14.3, 14.8, 14.7 14.4, 14.4, 14.5, 14.5 74.9, 73.6, 75.1, 74.9 74.7, 74.6, 74.8, 74.9 9.1, 9.0, 9.2, 9.2 9.2, 9.2, 9.1, 9.1 1 038 1 037

Issues

With one thread all 44 runs report identical issues, messages and taint traces included (the only difference is the generated config file name inside one nextcloud message). With eight threads master already reports different issues from run to run in six of the apps, and the branch differs from master by about as much and in the same issue kinds and files as two master runs differ from each other; the big Laravel project, drupal, doctrine/orm and bagisto report the same issues in all six runs.

…e reader can use

On a full run every argument passed to an untyped or native `mixed` param is
folded into Analyzer::$possible_method_param_types, and the workers ship the
unions to the main process, which combines them again. The only reader,
ClassLikes::findPossibleMethodParamTypes(), takes the methods that non-trait
classes of the project directories declare, if they have a location and their
file can be reported. So every call into a vendor method was recorded and then
thrown away: PHPUnit's assertSame(mixed, mixed) alone collects a union of every
value any test asserted.

Analyzer::addPossibleMethodParamType() now records a method only if its
declaring class is not a trait and is in the project directories, and the method
has a location, decided once per method. That is the part of the reader's test
that the config fixes for the whole run. The files whose issues can be reported
can still grow while the analysis runs (a plugin hook calling addFilesToAnalyze(),
addFilesToShowResults() or Codebase::addReportableFiles(), in the main process or
in a worker), so the reader keeps asking for them and the outcome does not depend
on when that happens.

The tests check the recorded types and the MissingParamType count for check()
and checkPaths(), that Psalter alters only the project's file, and the outcome
for a project directory include that a hook makes reportable before or during
the analysis, with the three APIs.
…lds a plain mixed

ClassLikes::findPossibleMethodParamTypes() skips a param whose inferred type
has mixed, and a plain mixed stays through every later combination
(TypeCombiner::scrapeTypeProperties()), so later arguments can no longer change
the outcome and the unions need not be combined any more, in the worker or when
the main process merges the workers' results.

A mixed from a loop isset and a union that failed reconciliation are dropped by
later combinations, so those are still combined.
…the platform separator

The project directories are resolved with realpath() and compared as prefixes
(FileFilter::allows()), so on Windows a path spelled with forward slashes is not
in them: the tests registered the fixtures that way, the declaring classes were
not in the project directories and nothing was recorded.
@alies-dev
alies-dev marked this pull request as ready for review November 16, 2026 03:06
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 749 71.7 $\color{gray}{\textsf{+0.5\%}}$ 25 907 53 460 682
✅ symfony 3 596 $\color{gray}{\textsf{-0.1\%}}$ 264.5 $\color{gray}{\textsf{+0.5\%}}$ 50 610 98 403 1 528
✅ doctrine-orm 380 19.0 $\color{gray}{\textsf{-0.5\%}}$ 3 481 6 143 0
✅ psl 617 24.4 $\color{gray}{\textsf{-0.6\%}}$ 1 375 5 615 1
✅ phpunit 455 18.2 $\color{gray}{\textsf{+0.2\%}}$ 1 731 3 410 18
✅ php-parser 226 11.9 $\color{gray}{\textsf{-0.6\%}}$ 17 154 21 245 0
✅ tempest 895 34.7 $\color{gray}{\textsf{+1.5\%}}$ 5 047 10 528 252
✅ amphp-amp 45 1.5 29 49 0
✅ webmozarts-assert 271 $\color{gray}{\textsf{-0.5\%}}$ 4.7 $\color{gray}{\textsf{-0.4\%}}$ 577 2 720 0
✅ guzzle-promises 44 $\color{gray}{\textsf{+0.1\%}}$ 1.6 $\color{gray}{\textsf{+1.3\%}}$ 155 434 2
✅ monolog 135 5.7 $\color{gray}{\textsf{+0.2\%}}$ 913 2 479 10
✅ drupal 4 839 236.8 $\color{gray}{\textsf{+0.5\%}}$ 97 591 169 293 583
Total 13 253 $\color{gray}{\textsf{-0.1\%}}$ 694.8 $\color{gray}{\textsf{+0.4\%}}$ 204 570 373 779 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head 9307b95 · base 0b1d9ca (merge-base) · workflow run

@github-actions github-actions Bot added the release:internal The PR will be included in 'Internal changes' section of the release notes label Nov 16, 2026
@alies-dev alies-dev self-assigned this Nov 16, 2026
@alies-dev alies-dev changed the title Perf: record usage-inferred param types only for methods in the project directories (one-thread run of a big app: -11 % wall) Perf: record usage-inferred param types only for methods in the project directories (one thread: -8 to -15 % wall on apps that analyse their tests) Nov 16, 2026
@alies-dev

Copy link
Copy Markdown
Collaborator Author

Re-measured on master 2da2040 (head 9d3151e).

Apple M1 Pro (10 cores, 32 GB), PHP 8.5.12, igbinary 3.2.17RC1, zend.assertions=1; load average at the start of a run 1.7 to 7.7 (median 3.7) with one thread and 3.9 to 12.4 (median 6.9) with eight. Every run is --no-cache. Runs of the two versions alternate (ABAB, then BABA). Peak is the main process's memory_get_peak_usage(). A change is marked only where the medians differ by more than 2 % (wall and analysis phase 3 %, peak 1 %) and by more than the spread of the runs in the cell. Taint analysis is on for the big private Laravel project, laravel-framework, wordpress, phpunit, composer and bagisto, and off for the others.

One thread (2 runs per version)

project runs wall s, master wall s, branch CPU s, master CPU s, branch analysis s, master analysis s, branch peak MB, master peak MB, branch
big private Laravel project 2+2 248.6, 243.0 214.3, 212.7 (-13 %) 245.9, 240.9 212.0, 211.3 (-13 %) 198.3, 192.8 164.4, 163.7 (-16 %) 7 525 7 516
phpunit 2+2 26.9, 26.7 23.1, 23.0 (-14 %) 26.7, 26.6 23.0, 22.9 (-14 %) 21.7, 21.7 18.1, 18.0 (-17 %) 1 276 1 272
doctrine-orm 2+2 26.7, 26.7 24.7, 24.9 (-7 %) 26.4, 26.4 24.5, 24.6 (-7 %) 20.5, 20.5 18.6, 18.7 (-9 %) 1 129 1 116 (-1 %)
composer 2+2 18.7, 18.5 18.6, 18.5 18.5, 18.4 18.4, 18.4 13.3, 13.3 13.3, 13.3 693 693
laravel-framework 2+2 56.2, 55.9 56.0, 56.0 55.8, 55.4 55.5, 55.4 43.8, 43.6 43.6, 43.5 1 747 1 747
mediawiki 2+2 127.6, 127.8 127.0, 126.8 127.0, 127.2 126.5, 126.2 111.8, 112.0 111.3, 111.1 2 093 2 093
symfony-notaint 2+2 80.5, 80.2 80.2, 80.4 79.8, 79.6 79.7, 79.6 60.6, 60.4 60.6, 60.5 3 291 3 291
drupal 2+2 64.9, 63.9 64.0, 64.1 64.2, 63.8 63.9, 64.0 51.0, 50.8 50.9, 51.0 1 970 1 969
wordpress 2+2 143.8, 144.2 144.0, 145.0 143.5, 143.9 143.7, 144.6 132.8, 133.2 133.0, 133.9 2 052 2 051
nextcloud 2+2 66.7, 65.5 65.6, 65.7 65.8, 65.5 65.6, 65.6 44.1, 44.2 44.1, 44.3 3 848 3 848
bagisto 2+2 38.5, 37.8 37.7, 37.8 37.8, 37.7 37.7, 37.8 22.4, 22.4 22.4, 22.4 1 838 1 838

The scan phase is the same on both sides in every cell, within its spread. One thread has no merge phase.

Eight threads (3 runs per version)

project runs wall s, master wall s, branch CPU s, master CPU s, branch analysis s, master analysis s, branch peak MB, master peak MB, branch
big private Laravel project 3+3 79.3, 78.4, 78.2 78.7, 77.4, 78.4 310.7, 307.9, 308.0 307.9, 304.5, 305.2 28.9, 28.5, 28.5 28.4, 28.0, 28.1 7 096 7 077, 7 078
phpunit 3+3 10.3, 10.1, 9.9 9.9, 9.9, 10.0 30.9, 30.9, 30.7 30.3, 30.3, 30.5 5.8, 5.9, 5.7 5.7, 5.7, 5.8 1 059 1 048 (-1 %)
doctrine-orm 3+3 8.1, 7.8, 7.8 7.6, 7.7, 7.9 31.6, 31.5, 31.6 31.0, 31.2, 31.1 3.3, 3.3, 3.3 3.2, 3.3, 3.3 784 775 (-1 %)
composer 3+3 6.9, 6.7, 6.6 6.7, 6.7, 6.7 23.1, 22.9, 22.9 22.9, 22.9, 22.9 2.4, 2.3, 2.3 2.3, 2.3, 2.3 443 443
laravel-framework 3+3 29.5, 29.1, 29.1 29.0, 29.0, 29.1 65.8, 65.4, 65.4 65.3, 65.2, 65.4 18.0, 17.9, 17.9 17.9, 17.9, 17.9 1 622 1 621
mediawiki 3+3 26.5, 26.3, 26.4 26.6, 26.8, 26.4 152.7, 152.2, 152.6 153.3, 152.3, 152.5 17.1, 17.1, 17.1 17.3, 17.1, 17.1 1 180 1 180
symfony-notaint 3+3 18.9, 18.5, 18.4 18.6, 18.4, 18.7 105.1, 104.8, 104.8 105.1, 104.8, 104.6 10.7, 10.7, 10.7 10.7, 10.7, 11.0 953 952
drupal 3+3 17.5, 17.4, 17.5 17.2, 17.4, 17.3 83.9, 83.7, 83.6 83.8, 83.6, 84.0 8.6, 8.6, 8.5 8.6, 8.6, 8.6 1 272, 1 273 1 272
wordpress 3+3 58.8, 56.9, 57.7 59.0, 57.4, 57.6 163.4, 161.8, 162.2 171.2, 162.6, 162.1 51.7, 50.3, 51.0 51.9, 50.7, 51.0 1 289 1 287, 1 288
nextcloud 3+3 16.2, 15.6, 15.4 15.6, 15.8, 15.4 86.1, 85.2, 84.9 85.3, 85.5, 84.9 7.6, 7.4, 7.5 7.5, 7.5, 7.5 1 144, 1 145 1 144, 1 145
bagisto 3+3 19.7, 19.9, 19.6 20.2, 19.6, 19.6 53.7, 53.8, 53.8 53.8, 53.8, 53.9 4.4, 4.4, 4.4 4.4, 4.4, 4.4 1 708, 1 709 1 708

The scan phase is the same on both sides in every cell. The merge phase of the big private Laravel project is 3.7, 3.4, 3.5 s on master and 3.6, 3.2, 3.2 s on the branch; no other app's merge phase moves by more than 0.2 s.

Size of possible_method_param_types in the main process at the end of the analysis with one thread (igbinary): big private Laravel project 4.5 MB (203 methods) on master against 83 KB (96 methods) on the branch, phpunit 2.6 MB (209) against 77 KB (199), doctrine-orm 1.6 MB (181) against 110 KB (128), composer 2.8 KB (2) against 6 bytes (0).

Issues: with one thread they are identical in all 44 runs (full strict_cmp of severity, type, file, line, column, message and taint trace, for every master/branch pair and for the two runs of each version); the one exception is the generated config file name psalm.bench-<variant>.xml inside a nextcloud UnusedIssueHandlerSuppression, identical once normalised. With eight threads master differs from itself between runs in six apps, so those runs cannot prove identity, and the branch differs from master by about as much as master differs from itself. Largest difference between two runs (added plus removed), master/master, master/branch, branch/branch: big private Laravel project 48, 48, 0; phpunit 30, 30, 9; composer 16, 16, 16; laravel-framework 14, 14, 14; symfony-notaint 2, 2, 0; mediawiki 0, 2, 2; wordpress 94, 126, 103 (six runs per version); doctrine-orm, drupal, nextcloud and bagisto none. Every (issue type, file) pair that differs between master and the branch also differs between two runs of the same version (wordpress: all 114 pairs, mostly Mixed* in src/wp-includes/blocks/*.php; with only three runs per version 22 pairs were not yet seen within one version). Examples: InternalClass in trait files (big private Laravel project), VersionCheckCommandTest (phpunit), TaintedCallable (laravel-framework), RedundantCondition in HttpClientTrait.php (symfony-notaint).

@alies-dev
alies-dev merged commit 6a962f1 into vimeo:master Nov 22, 2026
71 checks passed
@alies-dev
alies-dev deleted the perf-usage-param-types branch November 22, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:internal The PR will be included in 'Internal changes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant