Skip to content

improve memory footprint for read operations - #2102

Open
alperozturk96 wants to merge 7 commits into
masterfrom
improve-oome-read-data
Open

improve memory footprint for read operations#2102
alperozturk96 wants to merge 7 commits into
masterfrom
improve-oome-read-data

Conversation

@alperozturk96

Copy link
Copy Markdown
Collaborator

Changes

  • Catches OOME
  • Read only once remoteData.getResponses();

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

SpotBugs

CategoryBaseNew
Bad practice3131
Correctness2828
Dodgy code1414
Internationalization66
Malicious code vulnerability2626
Multithreaded correctness77
Performance77
Security44
Total123123

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 local MultiStatusResponse[] to avoid repeated calls during parsing.
  • Pre-size ArrayList instances based on the number of WebDAV responses to reduce resizing overhead.
  • Add an OutOfMemoryError catch in ReadFolderRemoteOperation to 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);
Comment on lines +84 to +87
} 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);
@nextcloud-android-bot

Copy link
Copy Markdown
Collaborator

@daniele-verducci

Copy link
Copy Markdown

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.
However, I get no feedback about the issue on the phone's screen, I just see "Loading..." and after a while "No files here".

image

I can see in the ADB logs the correct error:

Synchronized /InstantUpload/OpenCamera/: Unexpected exception
                                                                                                    java.lang.Exception: Not enough memory to read the contents of /InstantUpload/OpenCamera/

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>
@alperozturk96
alperozturk96 force-pushed the improve-oome-read-data branch from 3918414 to cbd5911 Compare August 14, 2026 11:20
@github-actions

Copy link
Copy Markdown
Contributor

SpotBugs

CategoryBaseNew
Bad practice3131
Correctness2828
Dodgy code1414
Internationalization66
Malicious code vulnerability2626
Multithreaded correctness77
Performance77
Security44
Total123123

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@alperozturk96

alperozturk96 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

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. However, I get no feedback about the issue on the phone's screen, I just see "Loading..." and after a while "No files here".

image I can see in the ADB logs the correct error:
Synchronized /InstantUpload/OpenCamera/: Unexpected exception
                                                                                                    java.lang.Exception: Not enough memory to read the contents of /InstantUpload/OpenCamera/

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).

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>
@github-actions

Copy link
Copy Markdown
Contributor

SpotBugs

CategoryBaseNew
Bad practice3131
Correctness2828
Dodgy code1414
Internationalization66
Malicious code vulnerability2626
Multithreaded correctness77
Performance77
Security44
Total123123

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown
Contributor

SpotBugs

CategoryBaseNew
Bad practice3131
Correctness2828
Dodgy code1414
Internationalization66
Malicious code vulnerability2626
Multithreaded correctness77
Performance77
Security44
Total123123

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown
Contributor

SpotBugs

CategoryBaseNew
Bad practice3131
Correctness2828
Dodgy code1414
Internationalization66
Malicious code vulnerability2626
Multithreaded correctness77
Performance77
Security44
Total123123

@daniele-verducci

Copy link
Copy Markdown

Right, sorry 🤦

@nextcloud-android-bot

Copy link
Copy Markdown
Collaborator

@alperozturk96

Copy link
Copy Markdown
Collaborator Author

Right, sorry 🤦

Client PR: nextcloud/android#17479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants