Repository navigation
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
Conversation
…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.
✅ Performance: unchanged · Types: unchanged
How to read this table
head 9307b95 · base 0b1d9ca (merge-base) · workflow run |
|
Re-measured on master 2da2040 (head 9d3151e). Apple M1 Pro (10 cores, 32 GB), PHP 8.5.12, igbinary 3.2.17RC1, One thread (2 runs per version)
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)
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 Issues: with one thread they are identical in all 44 runs (full |
When a full run infers param types from usage (it does so to count
MissingParamTypeand, under--alter, to fix it), every call to a method with an untyped or nativemixedparam adds the argument's type to a union kept per method inAnalyzer::$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'sassertSame(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 plainmixed, 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-cacheunless 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'smemory_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
mixedparams. 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.
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.
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)
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.