Repository navigation
Fetch the exported nodes of non-analysed files only when the result cache is saved - #6988
Merged
Merged
Conversation
…ache is saved The full-analysis save callback fetched them before doSave() decided not to save at all - a run on files passed on the command line or in editor mode never saves - so every such run parsed each file the analysed code depends on for nothing. doSave() now receives them as a callback and calls it only once the cache is known to be saved. WordPress src/index.php, which requires four files: 0.98 s -> 0.70 s with --debug and PHPSTAN_RESTART=none. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b250-30d4-72bb-8d3e-b0687619f435
ondrejmirtes
force-pushed
the
editor-mode-startup
branch
from
November 7, 2026 08:02
3c39d10 to
cb85689
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 2.2.13, single-file and editor-mode runs got slower, partly because of 3eb12b6. Its full-analysis save callback in
ResultCacheManager::process()calledaddNonAnalysedExportedNodes()beforedoSave()checked whether the cache is saved at all. A run on files passed on the command line, or in editor mode (--tmp-file/--instead-of), never saves the result cache. So such a run parsed every non-analysed file the analysed code depends on (scanned files, files reached through the autoloader) for nothing.doSave()now receives the exported nodes as a callback and calls it only after the checks that decide the cache isn't saved: only files passed, editor mode, errors in the dependencies, internal errors. A run that saves the cache gets exactly the same nodes as before.Wall time, best of 10 (two rounds of 5, one warm-up each)
analyse src/index.phpanalyse --debug src/index.phpanalyse -l 5 test.phpsrc/index.phprequires 4 files, and their exported nodes are no longer fetched. The trivial file depends on nothing, so it doesn't change. This PR doesn't fix the rest of the gap to 2.1.34. Most of it is OPcache: the restart activates it, and compiling PHPStan into it costs about 0.45 s per process (main process and spawned worker), which a one-file run never earns back.Setup: PHP 8.4.27 NTS on Linux x86_64, 16 cores, OPcache loaded but off for CLI (the default). 2.1.34 and 2.3.0 are the release PHARs. 2.3.x-dev (ec1df78) and this PR were built the same way (
compiler/bin/prepare+ box +resign.php, as in phar.yml), without a turbo binary next to them. wordpress-develop uses its ownphpstan.neon.dist(level 5). For 2.1.34 it ran in a copy with phpstan-phpunit 2.0.12 / phpstan-strict-rules 2.0.7 andphpVersion.max: 80599, because the current versions of those require 2.3.Locally:
make phpstan, andtests/PHPStan/{Analyser/ResultCache,Command,Parallel}.