speed up TrinaryLogic by kaja47 · Pull Request #4833 · phpstan/phpstan-src
kaja47
marked this pull request as draft
- Split variadic arguments for and() and or(). Common case of single argument doesn't allocate an array.
- Add static fields mirroring $registry to skip one level of indirection.
- Numeric values chosen that & and | is the same as min and max. and()/or() optimized accordingly.
- Inline trivial create() method.
- Remove one unnecessary access to registry in method create().
this loop runs 1.8x faster (php 8.4.16, jit off)
$t = TrinaryLogic::createYes();
for ($i = 10_000_000; $i--;) {
$t = $t->and(TrinaryLogic::createYes());
}
before: 1.125 s
now: 0.616 s
staabm
marked this pull request as ready for review
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