

FastImageCache – iOS library for quickly displaying images while scrolling - Me1000
https://github.com/path/FastImageCache

======
jamieomatthews
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.

~~~
michaelmior
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.

------
liuliu
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.

~~~
skyebook
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.

~~~
liuliu
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 to backup my claims obviously :)

~~~
skyebook
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)

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

~~~
mallorypaine
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?

~~~
cclogg
Actually you have my support for going manual. I still prefer to do all my
projects without ARC (and I'm not old-school, unless 2009 is old-school). I
just feel dirty everytime I use ARC, like I'm being sloppy haha. It also hides
a lot about memory management that new people might never learn (and thus be
in bigger trouble when something does go wrong). But I accept that it does
have major advantages...

One trouble now is you never know if a library or whatnot will be ARC so it
fragments things somewhat.

~~~
nielsbot
If you know how to use retain/release, then you shouldn't have any trouble
dealing with ARC edge cases... go ARC!

------
rbritton
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.

~~~
nielsbot
I think it can change from device to device too

------
sircambridge
A better solution then dealing with 60fps scrolling : Don't scroll, Flip!

~~~
dirtyaura
Not really, scrolling seems to be very natural interaction model on touch
screens. If you compare UI approaches of different apps, most of the popular
apps use scrolling, flipping hasn't really proven itself and it's a bit
gimmicky

