Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading image from CoreData at cellForRowAtIndexPath slows down scrolling
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COwhere are you loading your images from? is it a webserver or the local iphone albums ?
      singulars
    2. COHi Muhammad, the images are actually Facebook profile images of a user's Facebook friends. I used AFNetworking class to download them asynchronously and then display it and store them into Core Data + NSCache. When I was debugging this problem, I simplified the scenario into this: All images are already downloaded and available in CoreData and I merely load them from CoreData (imagine user viewing their Facebook album in offline mode). The table is still scrolling slowly and that's why I didnt mention about the downloading part in the question to simplify the issue. Thanks!
      singulars
    3. COMore clarification: If I used UIImageView+AFNetworking then I can display a table of a user's facebook friend's avatar images smoothly without scrolling problem. BUT this means that the app will have to download the images from the server again and again each time the app loads. I tried to use SDURLCache to cache the images offline but it is not working, and I like to have fine control of the caching so I decided to only download the profile images using AFNetworking but cache it for offline using CoreData myself.
      singulars
 

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