-
Notifications
You must be signed in to change notification settings - Fork 550
speed up TrinaryLogic #4833
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
base: 2.1.x
Are you sure you want to change the base?
speed up TrinaryLogic #4833
Conversation
src/TrinaryLogic.php
Outdated
| } | ||
|
|
||
| public function and(self ...$operands): self | ||
| public function and(self $operand, self ...$rest): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be
public function and(?self $operand = null, self ...$rest): self
because previously $operands could be a empty array (so no args given to and when invoked via splat
$trinary->and(...$moreTrinaries))
|
one bug in |
|
Sorry if I miss something obvious, but what's the point of keeping the $registry static with the addition of the new $YES $NO $MAYBE? Isn't it fully redundant now? |
- 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
|
This is really nice! I welcome your low-level knowledge like this here 😊 |
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