-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Avoid calling function repetitively in loop conditionals for better performance #16142
Conversation
Hi @lfluvisotto. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@orlangur, @osrecio and @ihor-sviziev Let me know when this PR gets merged then I will create the forwardport (2.3-develop) and backport (2.1-develop) |
Hi @lfluvisotto, please check #16027 (comment) on this. |
@osrecio what is your opinion? what do you think? it's relevant or not? |
Also @sidolov what is your opinion? what do you think? it's relevant or not? |
Also @okorshenko what is your opinion? what do you think? it's relevant or not? |
sizeof is an alias for count, in the opcode will be a new line or memory address whatever. Have a look at this benchmarch on Counting LoopsFor-loop test section: |
@orlangur @lfluvisotto specially I don't mind to accept such changes, but definitely these changes are manual and someone will add the same today or maybe tomorrow and no one will notice it. We had few examples of tries to improve code in general, but as result they were rejected:
Here were few reasons:
PS: remove function use might be automated, example: magento-engcom/php-7.2-support#31 If you have any questions - feel free to contact me in Slack |
Hi @lfluvisotto,
As I mentioned, please compare benefit of this change with the loop body execution time. You'll notice there is no measurable difference which would require such code complication. This fact won't change no matter how many people you will try to bother with review request :) @ihor-sviziev my main concern here is that we should not waste time on processing useless changes, especially when they slightly bloat the code. #9367 falls out of the list, I'll complete is, it was not about |
You can use for that in the CICD. https://github.com/kalessil/phpinspectionsea/blob/master/RULES.md Inspections Lists (Performance) > SlowArrayOperationsInLoopInspection > Slow array function used in loop |
@lfluvisotto this inspection is wrong as it is not a "slow" array function :) How can we use PhpStorm plugins on CICD? |
What is the tool used for CI/CD? Travis CI, right? |
Yep. And also Bamboo/Jenkins internally. |
I will have a look tonight how to call phpinspectionsea in Travis CI. |
Description
Avoid calling function repetitively in loop conditionals for better performance
Function sizeof replaced by count