Skip to content

Conversation

@dmiales
Copy link

@dmiales dmiales commented Jan 2, 2026

Problem:
Users with large photo and video libraries (5000+ files per folder) experience severe performance issues and OutOfMemoryError (OOM) crashes when opening folders. The application receives a massive XML file from the server and attempts to parse it entirely in memory, causing:

  • Application freezes and lagging (observed on Samsung S23+)
  • OOM errors during XML parsing
  • OOM errors in background synchronization processes
  • Data loss due to crashes during sync operations

Solution:
Rewrote the parsing block from the old ownCloud approach to a new streaming parser implementation. Additionally implemented batch processing for folders. This eliminates OOM errors and significantly improves performance and stability, even with 20,000+ photos and videos in a single folder.

Implementation details:

  • Add StreamingReadFolderRemoteOperation for memory-efficient folder reading using SAX parser
  • Add PropFindSaxHandler for streaming XML parsing of PROPFIND responses
  • Prevent OutOfMemoryError for folders with thousands of files by avoiding full XML loading
  • Integrate streaming parser into RefreshFolderOperation with fallback to legacy method
  • Add batch processing for large folders (500 files per batch) in FileDataStorageManager
  • Improve file upload collision handling in UploadFileOperation
    • Add content comparison for non-encrypted files when SKIP policy is used
    • Report SYNC_CONFLICT when file with same name has different content
    • Preserve old behavior for encrypted files and edge cases
  • Improve logging levels and add thread name tracking for better debugging

- Add StreamingReadFolderRemoteOperation for memory-efficient folder reading using SAX parser
- Add PropFindSaxHandler for streaming XML parsing of PROPFIND responses
- Prevent OutOfMemoryError for folders with thousands of files by avoiding full XML loading
- Integrate streaming parser into RefreshFolderOperation with fallback to legacy method
- Add batch processing for large folders (500 files per batch) in FileDataStorageManager
- Improve logging levels and add thread name tracking for better debugging

Signed-off-by: dmiales <dmiales@gmail.com>
Problem:
Users with large photo and video libraries (5000+ files per folder) experience severe performance issues and OutOfMemoryError (OOM) crashes when opening folders. The application receives a massive XML file from the server and attempts to parse it entirely in memory, causing:
- Application freezes and lagging (observed on Samsung S23+)
- OOM errors during XML parsing
- OOM errors in background synchronization processes
- Data loss due to crashes during sync operations

Solution:
Rewrote the parsing block from the old ownCloud approach to a new streaming parser implementation. Additionally implemented batch processing for folders. This eliminates OOM errors and significantly improves performance and stability, even with 20,000+ photos and videos in a single folder.

Implementation details:
- Add StreamingReadFolderRemoteOperation for memory-efficient folder reading using SAX parser
- Add PropFindSaxHandler for streaming XML parsing of PROPFIND responses
- Prevent OutOfMemoryError for folders with thousands of files by avoiding full XML loading
- Integrate streaming parser into RefreshFolderOperation with fallback to legacy method
- Add batch processing for large folders (500 files per batch) in FileDataStorageManager
- Improve file upload collision handling in UploadFileOperation
  - Add content comparison for non-encrypted files when SKIP policy is used
  - Report SYNC_CONFLICT when file with same name has different content
  - Preserve old behavior for encrypted files and edge cases
- Improve logging levels and add thread name tracking for better debugging

Signed-off-by: dmiales <dmiales@gmail.com>
- Replace inefficient trim().isEmpty() with isBlank() method

- Extract string literals to constants (LOG_EQUALS_QUOTE, UNKNOWN_PATH)

- Add size limits to StringBuilder to prevent memory leaks

- Combine nested if statements for better code style

Signed-off-by: dmiales <dmiales@gmail.com>
- Remove empty debug if blocks

- Remove DEBUG_XML constant and related debug logging

- Remove all Log_OC.d() debug statements

- Remove unused UNKNOWN_PATH constant

Signed-off-by: dmiales <dmiales@gmail.com>
@dmiales dmiales force-pushed the feature/additional-improvements branch from 7aaf1ad to 7f073c6 Compare January 2, 2026 12:05
- Combine nested if statements for better code style

- Remove hard size limit on StringBuilder, rely on periodic cleanup

- Add comments explaining memory safety of StringBuilder usage

- Optimize initial StringBuilder capacity to 512 bytes

Signed-off-by: dmiales <dmiales@gmail.com>
- Add @SuppressWarnings for PMD and SonarQube patterns

- Add @SuppressFBWarnings for SpotBugs

- Add codacy-disable comments

- StringBuilder fields are safe: cleared after each XML element and capacity trimmed periodically

Signed-off-by: dmiales <dmiales@gmail.com>
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.

2 participants