FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

iOS - First images in UITableView or UICollectionView cells take longer to load in and appear to get blocked

Open IainS1986 opened this issue 5 years ago • 0 comments

🐛 Bug Report

So I'm loading in images into a UITableView or UICollectionView cell. The view displays around 4 or 5 cells on the screen. Sometimes (around 80% of the time) when I first navigate to this screen, these 4 or 5 visible images take a second or two to appear - and then all appear simultaneously. After this, scrolling down the list is fine as all subsequent images load instantly (loading thumbnails from file, no web requests). The other 20% of the time, the first 4 or 5 cells appear instantly (this is not from the cache, I'm talking about clean reboots of the app from fresh so no memory cache).

Closing the view and returning to it also works fine (loading MemoryCache seems to work instantly every time).

I've tested multiple setups to see if it was something in the architecture I'm using outside of FFImageLoading...

  • Initially, I used MvxCachedImageView and set the ImagePath with a DelayBind.
  • Then I tried removing this and using ImageView directly, use a DelayBind to bind the url to a property and do my own ImageService.Instance.LoadFile(path)...
  • I've tried with Mvvm implementation of MvxTableViewSource and MvxCollectionViewSource for handling the cell reuse.
  • I've tried doing my own handlings for UICollectionViewDataSource and UICollectionViewDelegateFlowLayout to see if it was an issue in how Mvvm handles cell reuse.

All the above showed the same experience, first cells all seem to get blocked. I does appear to happen less often in a UITableView compared to a UICollectionView, but I have no hard stats to back that up.

Below are some example log outputs. This is how it looks when the first load of cells all get 'blocked' and then appear simultaneously (if I scroll while this blocking is happening, all subsequent cells get blocked too for longer and then ALL images finish at the same time...)

2020-12-18 12:39:08.234 App.iOS[10764:7793463] [Info] (LoadMeasurementFoldersViewModel) Navigated To
2020-12-18 12:39:08.252 App.iOS[10764:7793463] Image memory cache size: 401.5 MB
2020-12-18 12:39:08.276 App.iOS[10764:7793504] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 1, TotalPending: 1, TotalRunning: 1, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:39:08.277 App.iOS[10764:7793504] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 132MB, virtual_size: 836MB
2020-12-18 12:39:08.284 App.iOS[10764:7793503] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 2, TotalPending: 2, TotalRunning: 2, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:39:08.284 App.iOS[10764:7793503] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 132MB, virtual_size: 836MB
2020-12-18 12:39:08.289 App.iOS[10764:7793504] Generating/retrieving image: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/81.png
2020-12-18 12:39:08.294 App.iOS[10764:7793503] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 3, TotalPending: 3, TotalRunning: 3, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:39:08.295 App.iOS[10764:7793503] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 133MB, virtual_size: 836MB
2020-12-18 12:39:08.297 App.iOS[10764:7793503] Generating/retrieving image: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/51.png
2020-12-18 12:39:08.298 App.iOS[10764:7793512] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 4, TotalPending: 4, TotalRunning: 4, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:39:08.299 App.iOS[10764:7793512] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 133MB, virtual_size: 836MB
2020-12-18 12:39:08.306 App.iOS[10764:7793512] Generating/retrieving image: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/92.png
2020-12-18 12:39:08.309 App.iOS[10764:7793502] Generating/retrieving image: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/79.png
2020-12-18 12:39:08.677 App.iOS[10764:7793463] [Verbose] (HomeViewModel) View Disapeared
2020-12-18 12:39:08.679 App.iOS[10764:7793463] [Verbose] (LoadMeasurementFoldersViewModel) View Appeared
Thread started: <Thread Pool> #9
Thread started: <Thread Pool> #10
Thread started: <Thread Pool> #11
Thread started: <Thread Pool> #12
Thread started: <Thread Pool> #13
2020-12-18 12:39:09.776 App.iOS[10764:7793504] [PERFORMANCE] RunAsync - NetManagedThreadId: 7, NativeThreadId: 12, Execution: 476 ms, Key: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/79.png
2020-12-18 12:39:09.776 App.iOS[10764:7793519] [PERFORMANCE] RunAsync - NetManagedThreadId: 13, NativeThreadId: 18, Execution: 498 ms, Key: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/81.png
2020-12-18 12:39:09.777 App.iOS[10764:7793517] [PERFORMANCE] RunAsync - NetManagedThreadId: 11, NativeThreadId: 16, Execution: 490 ms, Key: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/51.png
2020-12-18 12:39:09.777 App.iOS[10764:7793502] [PERFORMANCE] RunAsync - NetManagedThreadId: 5, NativeThreadId: 10, Execution: 480 ms, Key: /var/mobile/Containers/Data/Application/88855ECC-69DA-4785-8D7C-86A2450817FC/Documents/92.png
Thread finished: <Thread Pool> #10

However, sometimes it works fine as expected and this is the log I'd see in that instance...

2020-12-18 12:36:35.284 App.iOS[10762:7792907] [Info] (LoadMeasurementFoldersViewModel) Navigated To
2020-12-18 12:36:35.301 App.iOS[10762:7792907] Image memory cache size: 401.5 MB
2020-12-18 12:36:35.326 App.iOS[10762:7792953] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 1, TotalPending: 1, TotalRunning: 1, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:36:35.328 App.iOS[10762:7792953] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 134MB, virtual_size: 844MB
2020-12-18 12:36:35.335 App.iOS[10762:7792945] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 2, TotalPending: 2, TotalRunning: 2, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:36:35.336 App.iOS[10762:7792945] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 135MB, virtual_size: 844MB
2020-12-18 12:36:35.340 App.iOS[10762:7792946] Generating/retrieving image: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/81.png
2020-12-18 12:36:35.344 App.iOS[10762:7792945] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 3, TotalPending: 3, TotalRunning: 3, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:36:35.344 App.iOS[10762:7792945] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 135MB, virtual_size: 844MB
2020-12-18 12:36:35.348 App.iOS[10762:7792953] Generating/retrieving image: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/51.png
2020-12-18 12:36:35.354 App.iOS[10762:7792945] [PERFORMANCE] Scheduler - Max: 16, Pending: 0, Running: 4, TotalPending: 4, TotalRunning: 4, TotalMemoryCacheHit: 0, TotalWaiting: 0
2020-12-18 12:36:35.357 App.iOS[10762:7792945] [PERFORMANCE] Memory - resident_size: 0MB, resident_size_max: 136MB, virtual_size: 845MB
2020-12-18 12:36:35.357 App.iOS[10762:7792952] Generating/retrieving image: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/92.png
2020-12-18 12:36:35.370 App.iOS[10762:7792944] Generating/retrieving image: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/79.png
2020-12-18 12:36:35.375 App.iOS[10762:7792946] [PERFORMANCE] RunAsync - NetManagedThreadId: 7, NativeThreadId: 11, Execution: 46 ms, Key: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/81.png
2020-12-18 12:36:35.375 App.iOS[10762:7792952] [PERFORMANCE] RunAsync - NetManagedThreadId: 9, NativeThreadId: 14, Execution: 30 ms, Key: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/92.png
2020-12-18 12:36:35.377 App.iOS[10762:7792952] [PERFORMANCE] RunAsync - NetManagedThreadId: 9, NativeThreadId: 14, Execution: 20 ms, Key: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/79.png
2020-12-18 12:36:35.380 App.iOS[10762:7792944] [PERFORMANCE] RunAsync - NetManagedThreadId: 5, NativeThreadId: 9, Execution: 44 ms, Key: /var/mobile/Containers/Data/Application/225706C4-487D-4297-996F-F9BF16C34FB7/Documents/51.png
2020-12-18 12:36:35.725 App.iOS[10762:7792907] [Verbose] (HomeViewModel) View Disapeared
2020-12-18 12:36:35.727 App.iOS[10762:7792907] [Verbose] (LoadMeasurementFoldersViewModel) View Appeared

As you can see, that time they loaded in around 50ms each which is how it works when scrolling through the cells, whereas sometimes the first load is taking 500ms each 80% of the time.

Any thoughts on what could be happening if its something I'm doing wrong my end?

Edit - Just for clarity. I am not talking about cached images here. The behaviours shown above in log outputs are from two different runs of a freshly installed app. My testing involved running the app, going to the screen, seeing if the behaviour occurs, and then killing the app fully and rebooting to test again

Expected behavior

The first set of visible cells should not have their calls to FFImageLoading blocked and instead behave the same as subsequent cells when loading.

Configuration

Version: Xamarin.FFImageLoading 2.4.11.982

Platform:

  • [X] :iphone: iOS
  • [ ] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [ ] :monkey: Xamarin.Forms

IainS1986 avatar Dec 21 '20 09:12 IainS1986