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
Performance opt on scandir() usage #5511
Conversation
- avoid tests inside the loop - avoid to double skip of `index.php`
This would probably be also interesting on PS 1.7. What do you think, @jocel1 ? |
$css_url = str_replace(_PS_ROOT_DIR_, '', $protocol_link.Tools::getMediaServer('').$cache_path.DIRECTORY_SEPARATOR.$file); | ||
$splitted_css[$css_url] = 'all'; | ||
} | ||
foreach (array_diff(scandir($cache_path), array('..', '.')) as $file) { |
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.
why not computing the array_diff outside of the foreach ?
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.
Are you sure it would be faster? I can't find any doc about this (not having assigned the array to any variables .. )
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.
The issue with computing the array_diff
within the foreach
is that you make the code computing the same value in every loop. By taking the array_diff computation out of the loop and into a variable, you gain some valuable microseconds, I'm sure -- moreover because you computation performs a scandir
, which touches upon the filesystem and therefore waaaaaay slower than any regular array creation :)
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.
My dubt was about to consider or not the (...) part of the loop to be
"inside" it
.. in other words I was not sure that this part of code is evaluated more
than one time ..
I'll do some tests to prove or negate this fact asap
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.
Please see this poc
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.
oups you're right, I mixed up with for / while cases. Seems it's also bad to review code on friday :D
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.
Always nice to have a reminder, thanks @ZiZuu-store :)
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.
eheh I'm here for this @xBorderie -_^
@xBorderie already made a PR for PS1.7 too ;) #5511 |
Ah yes, I see it: #5510. Thanks! |
Well, seems good to go. Waiting for a proper review by the dev, then both this PR and #5510 should be in :) |
f5db7a6
to
c189207
Compare
up :) |
Since the |
Thank you @ZiZuu-store |
/theme/cache
is empty after a clear cache.index.php