-
Notifications
You must be signed in to change notification settings - Fork 154
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
[New rule] Do not use in_array #143
Comments
I would say even: "Do not use |
We could start from this. But actually in most cases it’s quite obvious that it could cause performance issues in a loop, while real performance issues becoming on integration phases, when one method that contains in_array for few elements just called few thousands times. Example related to magento tedious/JShrink#90 |
The issue was discussed during the magento/architecture#290 and it was decided to not to introduce rule that may cause false-positive findings because its static nature (cannot measure actual performance). |
Sure, in_array() is a general practice in PHP and typical answer to question "how to kill performance" |
@andrey-legayev you are very welcome to join next public architecture discussion and share your thoughts. We are open to any improvements in case they provide a real value. |
How to optimize magento2 performance:
This is what I do during last 2 weeks. |
I do understand you point and the reason that stays behind the use of |
@andrey-legayev , I'd better promote better practices of using loops in general. There are many things that can kill performance, and
This is not about In the same time if you have an array of two items you're iterating through, and you do |
I measured in_array() performance for 1 element and isset() is still be faster. |
For example: |
@andrey-legayev I'm afraid, we are talking about different things there. Let me try to explain. There are two statements we are trying to mix:
That's why it was proposed to investigate and find more appropriate tool for such check. |
Rule
in_array
creating performance issue in many places when it used a lot of times.Reason
Performance diff: https://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset
It causes performance issues:
Implementation
The text was updated successfully, but these errors were encountered: