-
Notifications
You must be signed in to change notification settings - Fork 474
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
Improve performance by change count(array) to empty array [] comparison #917
Improve performance by change count(array) to empty array [] comparison #917
Conversation
compiler tests notice seems unrelated |
Hi, thank you, but I doubt this has real world performance implications. Did you measure it? |
You can check this benchmark https://phpsandbox.io/n/polished-violet-mwjd-llhvj
|
@samsonasik Cool tool, thanks for sharing the link 👍 I tried to re-run it couple of times and got wide range of numbers:
Factor 10x for the empty array. |
Yeah, but it's not obvious what it means for PHPStan from these benchmarks. I'll have to compare it with Blackfire. |
Weird, I don't reproduce the same times with 3v4l at all: Maybe a difference in opcache setup? I had to reduce the content of the array by a factor of ten, but I doubt this would have this kind of dramatic effect. I also have a different benchmark script that show similar results: https://3v4l.org/TNFbu (ie, no dramatic effect in one way or another) But I still prefer !== [] / === [] notation ! |
I prefer the |
AFAIR will php-src optimize code when you write using |
I doubt that there is one. In contrast to earlier PHP versions (I think from >=PHP 7.0) |
my assumption was wrong https://twitter.com/nikita_ppv/status/1482096003721355266?s=20 |
in #747 (comment) we concluded that this change is not worth it |
@ondrejmirtes @TomasVotruba this is for increase PHPStan performance improvement by replace count($array) === 0 or count($array) > 0 to empty array comparison $array === [] or $array !== [], it utilize rector's
Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector::class
.Rector probably needed to be part of CI workflow to verify it if it is approved, @ondrejmirtes what do you think?