Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early return Collectors when narrow-param is disabled #44

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 18, 2024

collectors store their data in the PHPStan result cache. we shouldn't pollute the result cache with data if we don't need it.

looking at the sources it seems these 3 collectors are only used for NarrowPublicClassMethodParamTypeRule and this rule has a configuration flag to early return if not enabled.

with this PR we now use the same configuration flag to early return in the related collectors


this PR came together because it turned out that one of the type-perfect collectors was by-far the most result-cache polluting component in our project:

mstaab@NB-COMPLEX-61 MINGW64 ~/AppData/Local/Temp/phpstan
$ grep 'collectorType' resultCache.php  > collectors.txt

mstaab@NB-COMPLEX-61 MINGW64 ~/AppData/Local/Temp/phpstan
$ sort collectors.txt | uniq -c
    283        'collectorType' => 'PHPStan\\Rules\\DeadCode\\ConstructorWithoutImpurePointsCollector',
      1        'collectorType' => 'PHPStan\\Rules\\DeadCode\\FunctionWithoutImpurePointsCollector',
    558        'collectorType' => 'PHPStan\\Rules\\DeadCode\\MethodWithoutImpurePointsCollector',
    351        'collectorType' => 'PHPStan\\Rules\\DeadCode\\PossiblyPureFuncCallCollector',
    391        'collectorType' => 'PHPStan\\Rules\\DeadCode\\PossiblyPureMethodCallCollector',
    133        'collectorType' => 'PHPStan\\Rules\\DeadCode\\PossiblyPureStaticCallCollector',
      3        'collectorType' => 'PHPStan\\Rules\\Traits\\TraitDeclarationCollector',
     34        'collectorType' => 'PHPStan\\Rules\\Traits\\TraitUseCollector',
    947        'collectorType' => 'Rector\\TypePerfect\\Collector\\ClassMethod\\PublicClassMethodParamTypesCollector',
   4765        'collectorType' => 'Rector\\TypePerfect\\Collector\\MethodCall\\MethodCallArgTypesCollector',

after his PR the result-cache of said project shrunk by ~16% in file-size - because we don't use narrow_param in our projects - which in turn makes phpstan analysis faster and less memory hungry

collectors store their data in the PHPStan result cache. we shouldn't pollute the result cache with data if we don't need it.
@TomasVotruba
Copy link
Member

Makes sense 👍

@TomasVotruba TomasVotruba merged commit fcb0ea2 into rectorphp:main Sep 18, 2024
6 checks passed
@TomasVotruba
Copy link
Member

Thanks 👏

@staabm staabm deleted the no-collect branch September 18, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants