Skip to content
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

Micro-optimize with in_array() #2618

Merged
merged 1 commit into from Sep 12, 2023
Merged

Micro-optimize with in_array() #2618

merged 1 commit into from Sep 12, 2023

Conversation

zonuexe
Copy link
Contributor

@zonuexe zonuexe commented Sep 12, 2023

These points are definitely not the bottleneck, but the chain of comparisons is compiled into fewer bytecode instructions by in_array().

It appears to be valid not only for method calls and property accesses, but also for comparing variables twice.
https://3v4l.org/QQQMr/vld

@zonuexe zonuexe changed the base branch from 1.11.x to 1.10.x September 12, 2023 12:28
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@thg2k
Copy link
Contributor

thg2k commented Sep 12, 2023

Does this bring a measurable performance benefit? Because i have the feeling you are sacrificing readability for a negligible (or possibly negative) performance change.

@ondrejmirtes
Copy link
Member

This is fine, I like it 👍 Although PHP itself could optimize this by itself when it sees this code pattern.

@ondrejmirtes ondrejmirtes merged commit 860372f into phpstan:1.10.x Sep 12, 2023
411 of 415 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants