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

Avoid calling function repetitively in loop conditionals for better performance #16142

Conversation

lfluvisotto
Copy link
Contributor

Description

Avoid calling function repetitively in loop conditionals for better performance
Function sizeof replaced by count

@magento-engcom-team
Copy link
Contributor

Hi @lfluvisotto. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on Pull Request changes
  • @magento-engcom-team give me new test instance - deploy NEW test instance based on Pull Request changes
  • @magento-engcom-team give me {$VERSION} instance - deploy Vanilla Magento instance for Issue or Pull Request

For more details, please, review the Magento Contributor Assistant documentation

@lfluvisotto
Copy link
Contributor Author

@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)

@orlangur
Copy link
Contributor

Hi @lfluvisotto, please check #16027 (comment) on this.

@lfluvisotto
Copy link
Contributor Author

@osrecio what is your opinion? what do you think? it's relevant or not?

@lfluvisotto
Copy link
Contributor Author

Also @sidolov what is your opinion? what do you think? it's relevant or not?

@lfluvisotto lfluvisotto requested a review from sidolov June 14, 2018 21:58
@lfluvisotto
Copy link
Contributor Author

Also @okorshenko what is your opinion? what do you think? it's relevant or not?

@lfluvisotto
Copy link
Contributor Author

@orlangur

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:

http://phpbench.com/

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Jun 15, 2018

@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:

  1. these PRs are manual and not adding any checking that we didn't introduced such issues again, so root of the issue is not fixed
  2. it covers a lot of changes in different places of magento, so it will be hard to do regression change in path release, it will be much better to add it to 2.3-develop branch, where full regression testing will be executed during preparing release
  3. usually such PRs are really huge, it will take a lot of time to accept them and as result - unable to merge, because there are a lot of another PRs that getting merged every day that are conflicting with these changes

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

@orlangur
Copy link
Contributor

Hi @lfluvisotto,

Have a look at this benchmarch on Counting LoopsFor-loop test section:
http://phpbench.com/

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 php-cs-fixer application actually.

@lfluvisotto
Copy link
Contributor Author

lfluvisotto commented Jun 15, 2018

@orlangur

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

@orlangur
Copy link
Contributor

@lfluvisotto this inspection is wrong as it is not a "slow" array function :)

How can we use PhpStorm plugins on CICD?

@lfluvisotto
Copy link
Contributor Author

lfluvisotto commented Jun 15, 2018

What is the tool used for CI/CD? Travis CI, right?

@orlangur
Copy link
Contributor

Yep. And also Bamboo/Jenkins internally.

@lfluvisotto
Copy link
Contributor Author

I will have a look tonight how to call phpinspectionsea in Travis CI.

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

Successfully merging this pull request may close these issues.

4 participants