-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Disabling sorting in glob and scandir functions for better performance #16052
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
Disabling sorting in glob and scandir functions for better performance #16052
Conversation
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 job @lfluvisotto!
No benchmarking needed, in article it was something like 25% but even 5% would be worth such improvement.
Didn't grep all over the code for the glob
and scandir
occurrences, I assume this was already done by PR author.
Hi @orlangur, thank you for the review. |
Hi @lfluvisotto. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
This was a really really REALLY bad idea. The rest of the changes in this PR were fine - they are made to functions were there was no expectation of sorting. I doubt it saved more than 100ms for unit testing and deployment, but that is ok. The problem is forcing a non-standard default behaviour in general purpose classes. And it is forced - there is no way to actually turn sorting back on AND use the file access classes. The benchmark from https://www.exakat.io/php-likes-sorting/ was irrelevant. That benchmark was for sorting 26,000 files that matched the pattern to begin with. Your not sorting thousands of files, at most hundreds, more likely dozens. Example: A magento installation with 100,000 files, 260 of them are xml files The default behaviour of glob searches is to sort. Everyone expects them to sort. Short of using the glob function directly[and therefore losing all the benefits of a standardized file system set of classes] there is no way to sort other then to sort the array of files which are returned. Which will add 200ms or more since array sorting in PHP is less effiicient! [See the same article above]. Now, WHY does everyone want sorting to take place by default? Simple, whenever we operate on a list of files, we don' have to provide any advanced "work on file X before working on file Y" programming logic. We just name our files appropriately. Look in your php/conf.d folder and you will immediately see it: Why do we do this in a very low level system function instead of higher level code? Because it is stupid to optimize hundreds of thousands of applications when you can optimize a single system function. And hey, YOU don't have to optimize it, thousands of programmers have spent decades optimizing it for you. |
Disabling sorting in glob and scandir functions for better performance
Description
Disabling sorting in glob and scandir functions for better performance
https://www.exakat.io/php-likes-sorting/