Repository navigation
Add --debug-performance=PATH performance summary and dump - #14737
Conversation
--debug-performance takes an optional value. Without it, the run prints the stages, the slowest files and the hottest statements and function-likes in absolute time. With =PATH it also writes the measurements as one JSON document for every output format. The in-memory Perf\Collector is a static, dependency-free class that is loaded before the autoloader. Forked workers hand their records to the main process in the result of their Shutdown task. Off, each hook is one static bool test and nothing is recorded, sent or written. Removes the ms-per-node timing (function_timings, NodeCounterVisitor) that the summary replaces.
Add a page with jq examples for the dump, a Chrome trace filter and the privacy note, and link it from the command line usage page.
The fixture handler ignored its parameter, which self-analysis reports as PossiblyUnusedParam.
…mance # Conflicts: # src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 32bf4a4. Configure here.
With an output format other than the console ones, the run printed no statistics at all (vimeo#9789). Now the timing and memory line, the type inference summary, the --stats output and the --debug-performance summary go to stderr through the progress, as plain text, so stdout stays the report and --no-progress keeps stderr empty. The memory peak the dump holds is still the one printed.
✅ Performance: unchanged · Types: unchanged
How to read this table
head e36455a · base 9def453 (merge-base) · workflow run |
|
Overhead on the M1 (WordPress 6.8.3, taint on,
|
--debug-performance=PATH performance summary and dump
…put formats" This reverts commit 9dff44e.
…handlers without per-call cost off - Statement executions and function-like passes of 1 ms or more are aggregated per place with their number of passes; hot and top come from the aggregates. - The dump is a Trace Event Format object (traceEvents), which Perfetto opens. - Provider handlers are wrapped once at registration while collecting, and EventDispatcher keeps its original loops. - origin is psalm only under Psalm\Internal; the startup collision check is a realpath of the directory plus the file name, with the write-time inode guard kept. - The dump is written to PATH.tmp and renamed; a failed write warns on stderr even with --no-progress.
…th Psalm writes The temporary file of the dump is made by tempnam() next to it and gets the mode of the dump it replaces, so a user file named PATH.tmp is not touched. The write-time guard checks the baseline of --set-baseline and every report path, and the start-up check leaves a .. after a symlink to the file system.
Cut the tests to one end-to-end case per promise of the option and the unit cases of the collector. The stage assertion pins the shape of the sequence: the number of scan rounds depends on the PHP version, as the stubs are preloaded below PHP 8.6.
- Write the dump directly to PATH; drop the temporary file, the mode copy and the whole path-collision guard (Psalm guards none of its other outputs). - EventDispatcher times a callable that the analyser checks, through one Collector::timed(); the accounting of handler time is in one place. - worker records are merged through recordStatement()/recordFunction(). - hot and top are one list of the 50 largest records per kind. - traceEvents args hold only the path; the wall time of a file is the difference of its rounded endpoints. - taint.resolver_tasks is resolver_rounds; the parser counts are not dropped by the counts of the storages. - Keep only the tests of critical and simple parts.
A function-like pass's own time is its wall time minus the passes over other function-likes that ran inside it (closures, parent constructors, methods analysed on demand). hot.functions is ranked by it and the console shows it before the total.
|
Overhead re-measured after the merge of master, at
Issues are identical in all nine runs ( |
… dump steps[] names the parts of a stage (config, preload, scan.stubs, scan.project, taint.resolve, output, ...), the console shows those that take 1 % of the run under their stage, and the trace has lanes for stages, steps, pools and, in each worker, when it worked and when it waited.
…t honestly - restart is restart.check, and env.restarted says whether this is the process Psalm restarted. - checkPaths() has the scan.setup steps of check(). - Steps that span a whole stage alone are gone; the scan rounds keep their names. - The console leaves out statements and functions under 10 ms of their own time. - One ranking helper, wrap() through timed(), and a unit test of the merge of worker data.
- Remove traceEvents (the viewer exports a trace), files[].mem_bytes, totals.children_max_rss_bytes and the parser counts from counts.
- php_bytes is php_end_bytes; workers report php_peak_growth_bytes; the payload size of a pool is a plain int, absent when not measured.
- Add pools[].cpu_us, parser {parses, cache_hits}, hot.min_us and hot.limit, a PluginInit hook per plugin and the phar name in the paths of files in other phars.
… of scanned files - The scan pool is released before its CPU time is read, so the workers are reaped and their time is the pool's. - scan.populate has the steps populate.classlikes, .methods, .files and .dependents, and taint has taint.prepare and taint.resolve. - A scan record has the size of the file contents the scanner read. - performance.md says what may change between releases.
|
Final overhead numbers at WordPress 6.8.3, taint on,
Issues are identical in all nine runs (
At 8 threads the issue lists differ between runs only where master differs between its own runs (WordPress |
- plugins[] holds the initialisation time of each plugin; env.plugins and the PluginInit hook rows are gone. - Workers report peak_growth_bytes, scan records size_bytes, env has the pid. - The summary prints the viewer link once, lists plugin initialisation on its own, and omits empty hot lists. - A stubs step covers the visit of the configured stubs.
* feat: add the performance report viewer at /perf/ Static page that renders the JSON file written by `psalm --debug-performance=PATH` (vimeo/psalm#14737): timeline of stages, steps, pools and workers, hot code, plugins, files and memory. The file is read in the browser and never uploaded. * fix: escape dump values and enforce no network access with a CSP

--debug-performancenow prints where a run spent its time and memory: stages, workers, the slowest files, the hottest statements and function-likes, and the time spent in plugin and provider handlers.--debug-performance=PATHalso writes all of it to a JSON file, which https://psalm.dev/perf/ shows as charts and tables in the browser.WordPress
wp-includes/html-apiwith #14653 reverted,psalm --threads=1 --debug-performance=perf.json:and on stderr:
Performance dump written to perf.json, open it in https://psalm.dev/perf/.The JSON has the top-level keys
schema,env,totals,stages,steps,plugins,pools(with their workers),files,hot,hooks,counts,parserandtaint;docs/running_psalm/performance.mddescribes them. The old "Slow-to-analyze functions" block (ms per node) is replaced. Without the option nothing is collected.