2

I am trying to avoid rendering delays in UICollectionViewController by pre-caching subviews of cell contentView in NSCache but it seems I miss to activate them properly since there is a delay in rendering cell when user scrolls to it (scrolling freezes, but first time only!). When user comes back, the same view is rendered smoothly. So it seems that pre-caching a simply initialized view is not enough and I need to do something more with the view in order to render it faster. How do I do it?

The current flow is the following:

  1. Render collection view with 10 cells and pre-cache all 10 cell views (i.e. cachedView -> contentView -> cellView)
  2. Scroll forward through the first 5 cells seeing rendering/scrolling delays
  3. Scroll backward to the first cell smoothly, no delays
  4. Scroll forward again through the first 5 cells smoothly, no delays
  5. Scroll forward through remaining cells seeing rendering delays
  6. At this point all cell views are activated(?) so scrolling backward and forward is smooth.

Some details:

  • A cell takes the whole screen.
  • cellForItemAtIndexPath replaces cached view (removes cell.contentView.subviews.first and adds another view from cache)
  • Cached view contains images.
  • Rendering the cached views to an image before scrolling does NOT speed up rendering cells.
  • Not using cached views leads to rendering/scrolling delays all the time
Andrei
  • 10,918
  • 12
  • 76
  • 110
  • When you say pre-cache, you mean pre-fetch data from an internet datasource ? Why are you caching the cells ? – Lefteris Oct 31 '16 at 09:57
  • The data was already downloaded, but it still takes longer time to render views first time. I am curious what can be done to pre-load view completely so it's cached completely. Just view initialization does not do everything... – Andrei Oct 31 '16 at 11:28
  • I suspect it's related to image views. – Andrei Oct 31 '16 at 11:29
  • Your approach I believe is wrong. There is no reason to pre-cache views. Show us what you are doing in the UICollectionView datasource (cellForItemAtIndexPath), because you are doing something wrong there to has such a performance hit – Lefteris Oct 31 '16 at 15:07
  • The views are kinda complex and have many subviews with images and effects e.g. blur, shadows etc. If I don't cache them, the scrolling freezes all the time. With cache it happens just the first time the cell is shown. – Andrei Oct 31 '16 at 15:18
  • That's why I asked. You shouldn't precache the view, but rather pre-cache the image with the blur effect and shadow. Also the CALayer flag for shouldRasterize should be set to YES. As a general rule, you should minimize the code in the cellForItemAtIndexPath delegate and move logic outside. But you shouldn't render the entire cell and save it. – Lefteris Oct 31 '16 at 16:07

0 Answers0