0

I have a problem. I have a UITableViewCell with images. The images are dynamically loaded from the application bundle. The function is about 200 lines with a lot of if satements in it. I basically extract the icon of the file acording to the suffix of the file, if the file is an Application I parse the info.plist and extract the filename of the icon. if the filename in the plist has no suffix I append it and then I chose the biggest icon. The function then returns the fileURL of the file either in my app bundle or in the app bundle of the app I parsed. I also do more stuff, but thats to complicated to explain.

I am already using SDWebImage, thats why I return a NSURL and not the UIImage.

The problem is, that the scrolling is lagging very hard on older devices without the A7 CPU. My thought is that I put the function in another NSOperationQueue, but I am not quite sure because I am already using the SDWebImage with compblock. The images dont have to be loaded instant, it can take some, meanwhile I display a placeholder image.

Does anyone have an idea how I can make this fluid?

Thanks, David

I just fixed my issue, I executed my own NSUserDefault with costume en- and decryption multiple times in on function! I fixed it by minimizing it and calling it once and store the value. Thanks for all your help!

David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98
  • `SDWebImage` is really meant to work for URL of web resource, since it relies heavily on http caching. You should write your own image loader and not use `SDWebImage`. IN this loader you can use `NSCache` to speed up the loading of images. Also have a look at this: https://github.com/path/FastImageCache – rckoenes Jul 30 '14 at 09:09
  • Can you post some of your code? – Duyen-Hoa Jul 30 '14 at 09:18

2 Answers2

0

This sample may help you: https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html

The general rule is: the main thread is just for changing your UI. Other works should be done in another thread. Try to move your code to a background thread.

Duyen-Hoa
  • 15,384
  • 5
  • 35
  • 44
0

are you parsing the plist file each time a table view cell is displayed? if yes => parse the plist file only once, save the result somewhere in memory, and use that instead. this is "lazy/cached loading". an NSDictionary is probably a good choice for this. keys are the keys that you are using to decide which image to display. and the values should be NSURL objects.

This should make the whole process much faster.

Michael
  • 6,451
  • 5
  • 31
  • 53
  • Hi, sorry for the late answer, I am just implementing a caching function. on the first TableViewLoad all paths of the loaded images are saved in a .plist in /Library/Caches/iconCache.plist. The key is the application name and the object is the image path, so it should be faster too. In addition I am thinking of using SVG files instead of PNG files, so I dont need to load the .png files, but then I need to draw the SVG file everytime, do you think this is quicker? – David Gölzhäuser Jul 31 '14 at 06:27
  • @DavidG. caching into a file is almost always a bad idea. I was once able to improve performance by just disabling the file-cache, because you can waste many CPU-cycles before going to the hard disk becomes a performance improvement! It can be really counter-intuitive sometimes... if the plist-file is just a cache, have you tried not saving it to a file but keeping the structure it represents in memory and keeping it there? BTW, you don't save RAM-space by saving the data to a file... – Michael Jul 31 '14 at 08:16
  • @DavidG. as for PNG vs. SVG... i really have no idea which format can be loaded faster. you'd just have to measure this. But I think the performance bottleneck is somewhere else, because in one app of mine I have a different image (in PNG format) in each table view cell, and they are all loaded from the app-bundle, with an ordinary `UIImageView` and `-[UIImage imageNamed:]`, and it runs smooth on an iPhone3GS with iOS 6... – Michael Jul 31 '14 at 08:20
  • I just fixed my issue, I executed my own NSUserDefault with costume en- and decryption multiple times in on function! I fixed it by minimizing it and calling it once and store the value. Thanks for all your help! – David Gölzhäuser Aug 02 '14 at 16:53