-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: reduce memory consumption of scans #41272
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
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 |
|
Ok, but this made it nearly 2x as slow, so was this really a good tradeoff? |
Summary
array_filteris 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_filtercreates 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$childrenis large.On the other hand, a foreach loop initializes an empty array
$childFoldersand then iterates through the$childrenarray, only adding elements to$childFoldersif 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