-
Notifications
You must be signed in to change notification settings - Fork 9.4k
fix: cache count() results for loops #18680
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
Conversation
Hi @DanielRuf. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@DanielRuf such change is not needed, see #16027 (comment) for more details. |
Not 100% true. Did you check the benchmarks? |
With this the compiler can apply AOT optimizations. |
Keep in mind that this saves many OP codes and utilizes the AOT benefits. Anything else is bad practice in general (cache immutable values). |
Please provide relevant benchmarks, in the ones provided loop body consists of just one assignment and obviously there will be a difference. |
See the 3v4l link, the second example in the middle uses a cached |
Loop body is too small and nonrealistic here, just compare to a real code you changed. What I'm trying to say is that such change does not give measurable boost in a real loop while obviously it makes some difference in a synthetic test. |
I'll create a OP code report using VLD in the next days. And yes it bringt better performance in big shops. |
This is how small benchmarks are generally done on the lowest level. |
It's twice as fast in most cases without any further optimizations ;-) |
@DanielRuf thanks, will see then. |
Hi @sidolov, thank you for the review. |
cc @sidolov |
@DanielRuf please do not reopen without providing a proper benchmark. |
There is a proper benchmark. With cached |
If readability is an issue, I can add the variable into the loop definition. If we would throwaway every improvement, even these which make bigger shops and specific loops faster, we do not gain much more performance. |
Also @sidolov is from the core tram and I think his review was correct. |
If this change makes no sense for you and you decide that this should not be in master / next releases, well then I will think about wasting more of my free time to improve little parts of Magento 2 as this is a very unsatisfying experience (totally different opinions and knowledge about the inner working of the Zend engine and AOT optimization for loops). |
@DanielRuf this change has nothing to do with performance as I explained from the very beginning. Compared to loop body one Whether a person from core or not is irrelevant to code review when both persons have enough information. I talked to @sidolov today in Slack an he agrees that such changes are useless from performance perspective. I'm okay with changes if you introduce a variable named exactly
Still I'm insisting that you should understand this change has no measurable performance impact - not 0.1%, not even 0.01%, totally negligible. So, my only intention was to not waste time and other resources on changes not improving a product. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with changes if you introduce a variable named exactly $count
in each case like
for ($i = 1, $count = count($line); $i < $count; $i++) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for collaboration.
Hi @orlangur, thank you for the review. |
Hi @DanielRuf. Thank you for your contribution. |
Description
This improves the performance of a few loops which were running
count()
in every iteration.Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist