Folders with large number of files causes scroll to freeze and navigation to lag and causes ANR at times
- Dominant language
- Kotlin
- Stars
- 5.6k
- Forks
- 2k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 92
Description
### ⚠️ Before posting ⚠️
- [X] This is a **bug**, not a question or an enhancement.
- [X] I've [searched for similar issues](https://github.com/nextcloud/android/issues) and didn't find a duplicate.
- [X] I've written a clear and descriptive title for this issue, not just "Bug" or "Crash".
- [X] I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/).
### Steps to reproduce
### Preparation:
We will need a directory with 500 images at least. More images will make this bug even more obvious.
- I created an account at try.nextcloud.com.
- Downloaded the photos in Photos directory using my browser on pc.
- Copy and pasted them locally repeatedly until I had 500 pictures.
- Created a directory /Photos/LargeDir
- Uploaded all pictures there using my browser on pc.
## Case 1: Loading of the folder causes scroll to freeze
1. Browse to mobile app and then photos directory under all files menu.
2. Click LargeDir
3. Initiate a fling scroll immediately as the list of files appears on large dir.
4. You will see the scroll halts and resumes intermittently as the directory loads with the loader sign visible. It's worse if view is set to Grid instead of row.
5. After loading is completed, it no longer freezes during scroll.
## Case 2: Going back and forth in between directories causes very delayed transitions from one directory to another
- Navigate to Photos directory.
- Click on LargeDir
- As soon as it opens press back. (don't wait for it to complete loading)
- As soon as Photos directory opens, click LargeDir again.
- Repeat this 10 times in a row and keep repeating
- Transactions from photos dir to LargeDir and back will become increasingly laggy as you repeat the navigation more and more.
- In cases it'll even disregard clicks on LargeDir icon and will not navigate to LargeDir. A second click is required.
## Case 3: Moving pictures out of the directory causes freezing and ANR
1. Navigate to our LargeDir and wait for it to complete loading.
2. Select 50 pictures RANDOMLY in that directory. Attempt to move them to a different directory.
3. After choosing the destination directory, the loading icon on the LargeDir list will appear and at this point the list will freeze randomly just like in case 1. It'll keep freezing scroll until all files have been moved
These 3 bugs are making overall usability of the app very difficult. I hope I was able to give you proper reproduction steps. If you still need help to reproduce it, I can post videos of the issues.
### Expected behaviour
In none of the above cases it should freeze the UI to prevent user from interacting
### Actual behaviour
UI freezes and prevents users from interacting.
### Android version
12
### Device brand and model
Google Pixel 6
### Stock or custom OS?
Custom (explain in "additional information")
### Nextcloud android app version
3.21.0
### Nextcloud server version
I don't know, whatever try.nextcloud.com was running on Aug 13 2022. I no longer have access to the account.
### Using a reverse proxy?
I don't know
### Android logs
_No response_
### Server error logs
_No response_
### Additional information
It seems that during loading, a lot of updates are being pushed to the RecyclerView. Due to which it freezes the UI. I have experienced this with different apps that I've worked on in the past. I can run some profiling and debug this if there's nobody available to work on it.
The laggy navigation transition is most likely due to
1. A lot of clean up code on main thread in fragment onDetach or onDestroy
2. RecyclerView ViewHolders are not optimized so on layout inflate it's spending a lot of time inflating a large number of ViewHolders. Easiest solution to this is to use a shared pool of ViewHolders amongst all File List fragments. This way they'll only inflate the first time and will be re used regardless of the number of times fragments are swapped.
Contributor guide
Assessment
This issue has not been assessed yet.