-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix: reduce memory consumption of scans #41272
Conversation
Signed-off-by: Git'Fellow <[email protected]> Fix lint Signed-off-by: Git'Fellow <[email protected]>
To benchmark it myself, I need to upload a good number of images, pre generate all previews, delete the previews again and run occ files:scan-app-data? |
I do not understand the difference, you wrote twice the same thing from what I understand. If array_filter is worse than a loop doing the same thing an issue should be opened with the PHP project. |
https://externals.io/message/100452 |
On my tests, on different php projects, the foreach loop was always less memory intensive (i'm not analysing speed/performance here) once the array is big (>hundreds). In this specific case, I've tested with v8.1 only. |
/backport to stable28 |
/backport to stable27 |
/backport to stable26 |
foreach() has a lower memory footprint the most of the array_* functions, so when you can expect to get a few more entries in your arrays, use foreach. |
/backport to stable28 |
/skjnldsv-backport to stable28 |
/skjnldsv-backport to stable27 |
Summary
array_filter
is pretty memory intensive, specially in the context ofappdata_
folder where it can have thousands of folders. Construct the array in a loop instead.The
array_filter
creates a new array and populates it with elements that meet the filter condition. This means it creates a new array in memory to hold the filtered elements, which can be memory-intensive, especially if the original array$children
is large.On the other hand, a foreach loop initializes an empty array
$childFolders
and then iterates through the$children
array, only adding elements to$childFolders
if they meet the filtering condition. This approach doesn't create an additional array for the filtered elements, so it consumes less memory.Before
After
Test system
Checklist