Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading image from CoreData at cellForRowAtIndexPath slows down scrolling
    text
    copied!<p>I am working on a UITableView that is very much like the iOS's native Photo app: it has many rows with 4 image thumbnails in each row. (i.e. each UITableViewCell has 4 UIImageViews) All thumbnails loaded from Core Data.</p> <p>I have revised my implementation multiple times and I can see performance improvements, but it is still unable to scroll as smooth as the Photo app. </p> <p>I need advise on how to properly cache the photos for best performance. This is what I tried:</p> <p><strong>1. My first attempt (extremely lag when scrolling)</strong></p> <ul> <li>Images are stored with type Transformable in CoreData. </li> <li>In cellForRow function, each image is fetched from CoreData on the fly.</li> </ul> <p><strong>2. Second attempt (faster, but still lag a bit when scrolling)</strong></p> <ul> <li>Images are stored with type Binary Data with 'external storage' option ticked in CoreData.</li> <li>In cellForRow function, each image is first loaded from Core Data and then stored into NSCache in memory, so next time cellForRow fires, we will use the UIImage from NSCache directly if available.</li> </ul> <p>After using NSCache to cache images loaded from CoreData, scrolling is visibly faster but since images still have to be loaded from CoreData when it is not yet available in NSCache, scrolling will still be jerky from times to times.</p> <p>So, there must be a better way, I could preload all the images into memory but since there might be large number or rows of images so I didnt plan to preload the images at all.</p> <p>What else can I do to load the image faster in cellForRowAtIndexPath?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload