Free the usage graph after emitting errors#392
Open
ondrejmirtes wants to merge 1 commit into
Open
Conversation
processNode(CollectedDataNode) runs once per process. After processKnownCollectedUsages() has turned the accumulated state into errors, $traitMembers, $memberAlternativesCache, $blackMembers and $usageGraph are dead weight — measured at ~90k retained objects on a 2.4k-file codebase and about 55 MB of main-process peak RSS on a 25k-file one, held until the process exits. $typeDefinitions and $mixedClassNameUsages are kept: the DiagnoseExtension print() reads them after analysis. DebugUsagePrinter received its own copies of the analysed members earlier (PHP array value semantics), so debug output is unaffected — covered by the existing testDiagnose* tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrTvR9j1mW2NNNC8RkuTsF
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.
Problem
DeadCodeRule::processNode(CollectedDataNode)runs once per process, at result finalization in PHPStan's main process. AfterprocessKnownCollectedUsages()has turned the accumulated state into errors,$traitMembers,$memberAlternativesCache,$blackMembersand$usageGraphare dead weight retained until the process exits.Found while instrumenting PHPStan memory retention on the ShipMonk backend: a per-service retention census attributed ~90k objects to the rule instance on a 2.4k-file slice (
UsageOrigin,ClassMethodRef/ClassPropertyRef/usages,BlackMember), and an interleaved A/B benchmark on the full 25k-file codebase measured −55 MB main-process peak RSS (3.07 GB → 3.02 GB, consistent across duplicate runs) with byte-identical error output and no time cost.Change
Reset the four members at the end of
processNode().Deliberately kept:
$typeDefinitionsand$mixedClassNameUsages— theDiagnoseExtension::print()reads them after analysis (clearing them broketestDiagnoseMixedCalls& co., which is how they earned their exemption).DebugUsagePrinterreceived its own copies of the analysed members earlier (PHP array value semantics), so-vvvdebug output is unaffected.composer check:tests(702 tests),check:types,check:cspass.🤖 Generated with Claude Code
https://claude.ai/code/session_01NrTvR9j1mW2NNNC8RkuTsF