Uh oh!
There was an error while loading. Please reload this page.
fix: reduce memory consumption of scans - #41272
Conversation
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Fix lint Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
kesselb
commented
Nov 3, 2023
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? |
come-nc
commented
Nov 6, 2023
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. |
come-nc
commented
Nov 6, 2023
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. |
solracsf
commented
Nov 28, 2023
/backport to stable28 |
solracsf
commented
Nov 28, 2023
/backport to stable27 |
solracsf
commented
Nov 28, 2023
/backport to stable26 |
blizzz
commented
Nov 28, 2023
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. |
solracsf
commented
Nov 28, 2023
/backport to stable28 |
solracsf
commented
Jan 16, 2024
/skjnldsv-backport to stable28 |
solracsf
commented
Jan 16, 2024
/skjnldsv-backport to stable27 |
mrtumnus
commented
Nov 3, 2025
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