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

Model performance improvements #646

Conversation

MaxBoeh
Copy link
Contributor

@MaxBoeh MaxBoeh commented Apr 26, 2018

Did some (micro) optimizations mainly regarding model loading / data assignment.

Max Böhme added 2 commits April 21, 2018 21:53
…micro optimizations: Less array like access of the field name, less function calls

- BaseModel::_setFieldData: replaced while-list-each with foreach, reduced calls of isPropertyLoaded
@MaxBoeh MaxBoeh changed the title WIP minor performance improvements model performance improvements Apr 26, 2018
@MaxBoeh MaxBoeh changed the title model performance improvements Model performance improvements Apr 26, 2018
Copy link
Member

@Sieg Sieg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, Thanks for trying improving our code! I would like to request some improvements of your changes. Please check the comments.

@@ -985,8 +985,15 @@ protected function _update()
protected function _setFieldData($sFieldName, $sValue, $iDataType = \OxidEsales\Eshop\Core\Field::T_TEXT)
{
//preliminary quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L'))) {
if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
if (($sFieldNameIndex2 = $sFieldName[2]) === 'l'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use hungarian notations anymore. Check our coding styles agreements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't make complex conditions even more complex :) Try to improve the readability instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hungarian: I know, but wanted to keep the method in a consistent style. I changed it :)

Without the assignment within the condition we either need to assign the character before (including isset) or duplicate the conditioned code. I think both options are worse than the maybe-saving of an access of the 16 index, I reverted most of the condition

$cur = $this->getShopCurrency();
$currencies = $this->getCurrencyArray();
if (!isset($currencies[$cur])) {
$this->_oActCurrencyObject = reset($currencies); // reset() returns the first element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the coding standards. "_" and "hungarian" notations are not allowed in new code anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property already exists, renaming it because of a change of indentation would be too much for the addition of an "if" I think. Are you sure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxBoeh, you are right, sorry, haven't noticed. I thought it is some new one for caching. Thanks for clarifying.

@Sieg Sieg self-assigned this Apr 27, 2018
@Sieg
Copy link
Member

Sieg commented May 10, 2018

Hello @MaxBoeh, Thank you for your pull request. I have merged it at 43201c3 recently. Have a nice day!

@Sieg Sieg closed this May 10, 2018
@MaxBoeh MaxBoeh deleted the feature/minor-performance-improvements branch May 19, 2018 07:41
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.

2 participants