SwiftExamples icon indicating copy to clipboard operation
SwiftExamples copied to clipboard

SmoothScrolling: Images not loading or taking too long while scrolling fast

Open Michelasso opened this issue 7 years ago • 4 comments

Hi,

I have read your tutorial so I decided to check the full sample code, also to port it to tvOS (but I get the same exact issues in iOS). I have run many tests, also trying to fix it myself (fat chance!) and when fast scrolling in a way or another something goes wrong. Either few images do not get loaded at all or they may take even 10 seconds to show.

I have put some extra logging and it seems like the old operations get executed even if the current cell is much far away. (I mean, something like #311 and following are loading, with many other is the middle, while #663 is showing) That would increase the time to load, I suppose. Then there is the issue of some avatars not showing at all, but they show later scrolling aways and then back.

Then I noticed that just after launch the first page gets loaded twice. But if I define the page size as the number of visible elements:

userViewModelController.retrieveUsers(pageSize: collectionView.visibleCells.count) where in retrieveUsers() I added the parameter "pageSize" it seems to be fixed.

Last but not least... Any idea why I get this warning? It spams everywhere!

2018-08-06 11:28:15.665341+0200 CollectionView-tvOS[976:181832] prepareGeometry:1604: *** kCGColorSpaceModelRGB: bad numberOfChannels '3' for alphaInfo 'kCGImageAlphaNoneSkipFirst'
2018-08-06 11:28:15.670490+0200 CollectionView-tvOS[976:179840] prepareGeometry:1604: *** kCGColorSpaceModelRGB: bad numberOfChannels '3' for alphaInfo 'kCGImageAlphaNoneSkipFirst'

Actually i see that a big slowdown is caused by those messages, so they may be the root of the problem. I know it is just a tutorial, but it would help me greatly to understand why sometime it goes banana. Thanks!

PS: I forgot to mention that I am using Xcode 10 beta, iOS 12 beta and tvOS beta. Although with other programs I made using collection views the last issue doesn't present itself. Still if it works just fine for you it might be something with my environment.

Michelasso avatar Aug 06 '18 09:08 Michelasso

It was the beta OS... I have found out that it gave that message when executing

image = UIImage(data: data)

inside the function to download the images. Now I have just installed tvOS 12 beta 6 and that message eventually disappeared. Also MUCH improving the performances. Some images still do not get loaded, though, and they may still take few seconds to replace the avatar. Unless it is still caused by the beta OS, sure.

Michelasso avatar Aug 06 '18 17:08 Michelasso

Thanks for the update @Michelasso! I never tried the samples on tvOS. Especially on a real device. So, it's possible that there are some bugs or even just some portions of the code that don't perform particularly well.

andrea-prearo avatar Aug 08 '18 02:08 andrea-prearo

Hi @andrea-prearo, thanks for answering!

I actually get the same identical issues on iOS, tested on my iPad. Again, I have all my devices on beta OS (plus Xcode 10 beta), so that is most likely causing issues itself (it does for sure with the BoringSSL now, a new warning message appearing in iOS/tvOS 12 beta 6, slowing down the execution and thus probably ruining again the flow). The first page gets loaded twice by the app, though.

Oh well, in few weeks they'll all go GM, so I'll know better. Thanks again!

Michelasso avatar Aug 08 '18 09:08 Michelasso

Sounds good. Thanks!

andrea-prearo avatar Aug 11 '18 00:08 andrea-prearo