Add external file dependency tracking for incremental cache invalidation#5364
Draft
janedbal wants to merge 2 commits intophpstan:2.1.xfrom
Draft
Add external file dependency tracking for incremental cache invalidation#5364janedbal wants to merge 2 commits intophpstan:2.1.xfrom
janedbal wants to merge 2 commits intophpstan:2.1.xfrom
Conversation
Introduces ExternalFileDependencyRegistrar, a new @api service that allows extensions to declare that an analyzed file depends on an external (non-analyzed) file. When that external file changes, only the dependent analyzed files are re-analyzed instead of triggering full cache invalidation. This is an alternative to ResultCacheMetaExtension for cases where external data changes (e.g. Symfony DI container XML) should not cause full cache invalidation but rather surgical re-analysis of affected files only. The mechanism integrates with the existing result cache system: external dependencies are tracked during analysis, stored in the cache alongside regular file dependencies, and checked during cache restore. Co-Authored-By: Claude Code
Draft
2 tasks
Member
|
Smells a lot of like vibecoding, I don't like the API. I think a special Collector, especially now when we have CollectedDataEmitter on 2.2.x, might work better. |
- Use early exit (continue) instead of nested if blocks in ResultCacheManager - Add missing `use function count` in WorkerCommand - Remove same-namespace import in AnalyserTest - Fix mergeExternalFileDependencies: strip hashes from cached data in restore() before passing to ResultCache, matching the pattern used by regular dependencies Co-Authored-By: Claude Code
Contributor
Author
Do you mean the phpstan-symfony wont call any |
Member
|
I don't know. I posted phpstan/phpstan-symfony#455 (comment) after some thinking, this needs deeper analysis and a different idea. |
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.
Summary
ExternalFileDependencyRegistrar, a new@apiservice that allows extensions to declare that an analyzed file depends on an external (non-analyzed) fileResultCacheMetaExtensionfor cases where external data changes should cause surgical re-analysis of affected files only, not full invalidationMotivation
ResultCacheMetaExtensionis an all-or-nothing mechanism — when any extension's hash changes, the entire result cache is invalidated. phpstan-symfony uses this to track Symfony DI container changes, but any service definition change (even trivially adding a dependency via autowiring) causes full re-analysis of the entire project. On large codebases this is devastating.This PR adds a granular alternative: extensions register per-file dependencies on external files during analysis. When those files change, only the affected analyzed files (and their dependents) are re-analyzed.
See companion PR: phpstan/phpstan-symfony#478
Changes
ExternalFileDependencyRegistrarservice (@api) withadd(string $externalFilePath)methodFileAnalyserResult/AnalyserResultcarry external dependencies through the pipelineWorkerCommand/ParallelAnalyserserialize and aggregate external deps across parallel workersResultCacheManager:restore(): checks external file hashes, adds dependent files to incremental re-analysis listsave(): inverts and stores external dependencies with file hashesprocess(): merges cached + fresh external dependenciesTest plan
Co-Authored-By: Claude Code