Skip to content

perf: Prefilter methods that cannot return QueryBuilder - #780

Draft
realFlowControl wants to merge 3 commits into
phpstan:2.0.xfrom
realFlowControl:optimize/querybuilder-return-type-prefilter
Draft

perf: Prefilter methods that cannot return QueryBuilder#780
realFlowControl wants to merge 3 commits into
phpstan:2.0.xfrom
realFlowControl:optimize/querybuilder-return-type-prefilter

Conversation

@realFlowControl

Copy link
Copy Markdown
Contributor

Inspect declared method variants before argument-dependent selection and return early only when every variant definitely cannot return QueryBuilder. Uncertain, generic, mixed, and compatible variants continue through the existing resolution path.

Most method candidates do not return QueryBuilder. This conservative filter avoids ParametersAcceptorSelector and downstream work for definite negatives while preserving fallback behavior whenever the declaration is not conclusive.

Benchmark: uncached Sylius analysis of 2,366 files with eight workers, five runs per variant. Median elapsed time fell from 28.91 s to 28.45 s (-1.6%) and aggregate user+sys CPU from 176.22 s to 170.75 s (-3.1%).

Benchmark run locally using PHPStan 2.2.x and PHPStan-Doctrine 2.0.x on MacOS with PHP 8.5.7

realFlowControl and others added 3 commits July 22, 2026 18:09
Inspect declared method variants before argument-dependent selection and return early only when every variant definitely cannot return QueryBuilder. Uncertain, generic, mixed, and compatible variants continue through the existing resolution path.

Most method candidates do not return QueryBuilder. This conservative filter avoids ParametersAcceptorSelector and downstream work for definite negatives while preserving fallback behavior whenever the declaration is not conclusive.

Benchmark: uncached Sylius analysis of 2,366 files with eight workers, five runs per variant. Median elapsed time fell from 28.91 s to 28.45 s (-1.6%) and aggregate user+sys CPU from 176.22 s to 170.75 s (-3.1%).
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.

1 participant