Skip to content

perf: Reuse the QueryBuilder ObjectType - #779

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

perf: Reuse the QueryBuilder ObjectType#779
realFlowControl wants to merge 3 commits into
phpstan:2.0.xfrom
realFlowControl:optimize/querybuilder-object-type-reuse

Conversation

@realFlowControl

Copy link
Copy Markdown
Contributor

Create the QueryBuilder ObjectType once in the resolver constructor and reuse it for return-type compatibility checks.

The resolver is called more than 600,000 times in the measured workload. The ObjectType is immutable for this use, so allocating the same value for each method candidate only adds allocation and CPU overhead.

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.34 s (-2.0%) and aggregate user+sys CPU from 176.22 s to 169.68 s (-3.7%).

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
Create the QueryBuilder ObjectType once in the resolver constructor and reuse it for return-type compatibility checks.

The resolver is called more than 600,000 times in the measured workload. The ObjectType is immutable for this use, so allocating the same value for each method candidate only adds allocation and CPU overhead.

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.34 s (-2.0%) and aggregate user+sys CPU from 176.22 s to 169.68 s (-3.7%).
@realFlowControl

Copy link
Copy Markdown
Contributor Author

I do not fully understand why infection still fails, something is off

@staabm

staabm commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Trinary->yes() vs. !Trinary->no() mutations get killed by implementing a test which instructs the Trinary->maybe() case. I think in this case this means you need to test a union with multiple classes.

we don't necessarily need a green mutation testing build on each PR though

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