improve memory footprint for read operations - #2102
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces repeated WebDAV response-array access and attempts to improve memory behavior when parsing folder listings (regular files, trashbin, and versions) in the legacy owncloud remote operations.
Changes:
- Cache
remoteData.getResponses()into a localMultiStatusResponse[]to avoid repeated calls during parsing. - Pre-size
ArrayListinstances based on the number of WebDAV responses to reduce resizing overhead. - Add an
OutOfMemoryErrorcatch inReadFolderRemoteOperationto return a failure instead of crashing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| library/src/main/java/com/owncloud/android/lib/resources/trashbin/ReadTrashbinFolderRemoteOperation.java | Cache responses array and pre-size result list while iterating trashbin entries. |
| library/src/main/java/com/owncloud/android/lib/resources/files/ReadFolderRemoteOperation.java | Cache responses array, pre-size list, and add an OutOfMemoryError catch during folder reads. |
| library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java | Cache responses array and pre-size versions list while iterating version entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private void readData(MultiStatus remoteData, OwnCloudClient client) { | ||
| folderAndFiles = new ArrayList<>(); | ||
| MultiStatusResponse[] responses = remoteData.getResponses(); | ||
| folderAndFiles = new ArrayList<>(responses.length); |
| } catch (OutOfMemoryError e) { | ||
| mFolderAndFiles = null; | ||
| result = new RemoteOperationResult( | ||
| new Exception("Not enough memory to read the contents of " + mRemotePath, e)); |
| private void readData(MultiStatus remoteData, OwnCloudClient client) { | ||
| versions = new ArrayList<>(); | ||
| MultiStatusResponse[] responses = remoteData.getResponses(); | ||
| versions = new ArrayList<>(responses.length); |
|
stable22-IT test failed: https://www.kaminsky.me/nc-dev/android-library-integrationTests/2102-IT-stable22-13-53/debug/ |
|
Hey @alperozturk96 , I was able to replicate the OOM crash using the current prod library on a directory with 12k files, and can confirm that with the library from this PR the app does NOT crash.
I can see in the ADB logs the correct error: but nothing on the screen, so I fear that to an unbeknowing user, it may seem that the directory is effectively empty (or that the content has gone lost). |
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
3918414 to
cbd5911
Compare
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
This needs to be handled in client side. I will expose OOME then handle in client via different PR. |
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
|
Right, sorry 🤦 |
|
stable34-IT test failed: https://www.kaminsky.me/nc-dev/android-library-integrationTests/2102-IT-stable34-12-17/debug/ |
Client PR: nextcloud/android#17479 |


Changes
remoteData.getResponses();