Skip to content

Faster TypeCombinator#5934

Merged
staabm merged 2 commits into
phpstan:2.2.xfrom
staabm:fast-typec
Jun 25, 2026
Merged

Faster TypeCombinator#5934
staabm merged 2 commits into
phpstan:2.2.xfrom
staabm:fast-typec

Conversation

@staabm

@staabm staabm commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

the reproducer from phpstan/phpstan#14869 with n=300

before this PR

➜  phpstan-src git:(2.2.x) ✗ hyperfine 'php bin/phpstan analyze repro.php --debug' --runs=5
Benchmark 1: php bin/phpstan analyze repro.php --debug
  Time (mean ± σ):      8.525 s ±  0.066 s    [User: 7.835 s, System: 0.271 s]
  Range (min … max):    8.449 s …  8.630 s    5 runs
grafik

after this PR

➜  phpstan-src git:(fast-typec) ✗ hyperfine 'php bin/phpstan analyze repro.php --debug' --runs=5
Benchmark 1: php bin/phpstan analyze repro.php --debug
  Time (mean ± σ):      7.590 s ±  0.241 s    [User: 6.818 s, System: 0.278 s]
  Range (min … max):    7.314 s …  7.953 s    5 runs

=> 13 % faster

@staabm staabm requested a review from VincentLanglet June 25, 2026 13:14
$typesCount = count($types);
}

usort($types, static function (Type $a, Type $b): int {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sort function only re-arranges SubtractableType, ConstantArrayType.

if we know beforehand that $types cannot contain one of these types -> skip the sort which will not change the order of types anyway

@staabm staabm merged commit a9a9630 into phpstan:2.2.x Jun 25, 2026
671 of 672 checks passed
@staabm staabm deleted the fast-typec branch June 25, 2026 13:48
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