Live data from Hacker News

FastImageCache – iOS library for quickly displaying images while scrolling

github.com

11–20 of 35 posts

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#11
post #2

It does seem weird that they store the uncompressed image on the disk. I think that a benchmark on this comparing with compressed / decompress on CPU would be interesting because one is bounded on I/O, another is bounded by CPU throughput.

It might vary depending on the image format. http://imageoptim.com/tweetbot.html < This indicates that the disk throughput is more of a limiting factor than anything.

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#12

Whats the difference between this and SDWebImage, if any?? I cant see a ton of different API differences. Looks like this probably wont support ARC, though.

The big difference in how the cache is managed. SDWebImage has worked well when I've used it, but it's cache management is much more simplistic. I'd be curious to try FastImageCache on projects I've worked on to see if there's any improvement. Scrolling performance can be a tough thing to optimize for.

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#13
post #9
post #6

Earlier quoted context omitted.

It actually isn't all that surprising, we've hit similar bottlenecks where JPEG decompression on the iPhone ends up choking feeds that are scrolled through quickly. We didn't go the route of caching the uncompressed data on disk, though, we just keep the images in a maintained in-memory cache.

Exactly. I would think that a layered cache scheme probably could have the best of the two worlds (a good size of cached content on disk, and fast uncompressed image hit from memory). But using mmap'ed file instead of doing own layered cache seems less hassle. Also, you are doing decompression on a background thread, which shouldn't be much a choke on 4S and later devices (probably, again). I need to have some tests…

If you're using libdispatch on the 4S you might consider using a serial queue (for NSOperationQueue just set the maxConcurrentOperationCount to 1) as it starts to eat the CPU pretty quickly if you're trying to load a lot of images.

Even on the 5 I was surprised by how much it helped to have the images cached (no anecdotal data on the 5S as it came out way after we started caching)

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#14
As they made some note of, Core Animation is very picky about the image format you provide via the contents property. For example, if you retain a reference to a CGImageRef that you also assign to a CALayer's contents property, you will end up with at least double the memory usage if it's not in CA's preferred format and it makes a copy of it. In my experience doing that alone can help performance immensely.

I've since lost track of the Apple documentation that said it, but CA prefers 16-byte alignment and (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) for the pixel format.

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#16
post #15

It's not using ARC. Is this legacy code, or couldn't they get equivalent performance with ARC enabled?

Hello. Mallory Paine here. I wrote FIC. This is not legacy code...it should be trivial to convert it to ARC and performance should be unaffected. I'm a bit old school myself so I chose to write it with manual retains. Does this approach make the code more difficult for you to use within an ARC project?

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#18
post #15

It's not using ARC. Is this legacy code, or couldn't they get equivalent performance with ARC enabled?

Hello. Mallory Paine here. I wrote FIC. This is not legacy code...it should be trivial to convert it to ARC and performance should be unaffected. I'm a bit old school myself so I chose to write it with manual retains. Does this approach make the code more difficult for you to use within an ARC project?

Why would you write it with manual retains? Who doesn't use ARC at this point?

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#19
post #5
post #3

Earlier quoted context omitted.

One thing that is often overlooked when considering file I/O is that the kernel caches previously accessed files for fast reads. This, combined with the lazy-loading mmap() can prove for good performance with simultaneous low memory usage for something like an image cache. This technique is used on the iOS home screen - both the icon images and the rendered icon labels are stored as uncompressed bitmaps on disk and m…

Does mmapping the file mean that it'll block on file I/O if it's not already cached, though? I don't see any claims (haven't read the code) that it prevents this.

When the pages are first accessed, the file data is paged in, and yes, this will be a blocking operation. One way to mitigate this would be to force the data to be paged in using a background thread, so that the pages are live by the time Core Animation needs those bytes to render the layer. This page preheating isn't usually necessary for small images, which is the primary use case for FIC.

FIC really pays off in a scenario like Path's mobile app. We have many, many small-to-medium-size user images to display, and those images are competing for CPU time with all of the styled text labels we're drawing. The less CPU we have to devote to images, the faster we'll be able to scroll.

Re: FastImageCache – iOS library for quickly displaying images while scrolling

#20

Earlier quoted context omitted.

Hello. Mallory Paine here. I wrote FIC. This is not legacy code...it should be trivial to convert it to ARC and performance should be unaffected. I'm a bit old school myself so I chose to write it with manual retains. Does this approach make the code more difficult for you to use within an ARC project?

Why would you write it with manual retains? Who doesn't use ARC at this point?

If the rest of the project is non-ARC it's easier in my experience to write new additions that way as well. I've only been using ARC on newly-created projects because having to add -fobjc-arc or -fno-objc-arc to dozens of files in Xcode is very, very tedious.
Post reply on HN