Skip to content

Faster TrinaryLogic::maxMin()#5045

Merged
staabm merged 3 commits intophpstan:2.1.xfrom
staabm:trin
Feb 25, 2026
Merged

Faster TrinaryLogic::maxMin()#5045
staabm merged 3 commits intophpstan:2.1.xfrom
staabm:trin

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 25, 2026

analog #4833

Benchmark:

<?php

require 'src/TrinaryLogic.php';

$t = \PHPStan\TrinaryLogic::createYes();
for ($i = 10_000_000; $i--;) {
	\PHPStan\TrinaryLogic::maxMin(\PHPStan\TrinaryLogic::createYes(), \PHPStan\TrinaryLogic::createYes(), \PHPStan\TrinaryLogic::createYes(), \PHPStan\TrinaryLogic::createNo());
}

before

➜  phpstan-src git:(2.1.x) ✗ hyperfine 'php trinary.php'
Benchmark 1: php trinary.php
  Time (mean ± σ):      1.714 s ±  0.010 s    [User: 1.694 s, System: 0.016 s]
  Range (min … max):    1.702 s …  1.733 s    10 runs

after

➜  phpstan-src git:(trin) ✗ hyperfine 'php trinary.php'
Benchmark 1: php trinary.php
  Time (mean ± σ):      1.492 s ±  0.031 s    [User: 1.474 s, System: 0.014 s]
  Range (min … max):    1.464 s …  1.575 s    10 runs

relevant because of slow path in Wordpress

grafik

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm changed the base branch from 2.2.x to 2.1.x February 25, 2026 14:50
@staabm staabm marked this pull request as ready for review February 25, 2026 14:50
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm merged commit 4c2c1e2 into phpstan:2.1.x Feb 25, 2026
644 of 648 checks passed
@staabm staabm deleted the trin branch February 25, 2026 16:45
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.

3 participants