News for hackers. Stuff that matters.
Re:FastImageCache – iOS library for quickly displaying image... by liuliu on Monday October 21, 2013 @09:06PM (#6589211)
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.
Re:FastImageCache – iOS library for quickly displaying image... by conradev on Monday October 21, 2013 @09:20PM (#6589255)
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 mmap'd when needed into memory. The fast loading allows SpringBoard to aggressively recycle icon views.

Re:FastImageCache – iOS library for quickly displaying image... by Groxx on Monday October 21, 2013 @09:26PM (#6589278)
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.
Re:FastImageCache – iOS library for quickly displaying image... by mallorypaine on Monday October 21, 2013 @11:49PM (#6589703)
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 image... by Groxx on Tuesday October 22, 2013 @01:47AM (#6589984)
Aaah, all the text rendering, that lends more weight to storing them uncompressed. Hadn't thought of that, I was pondering more on the I/O being way slower than (uncontested, in retrospect) CPU of basic decompression.

Well, Path is amazingly smooth for how much styled stuff is in it, so nice work :) The UI really does stand out in how well it's done.

Re:FastImageCache – iOS library for quickly displaying image... by nielsbot on Tuesday October 22, 2013 @02:13AM (#6590070)
I've used this to track down my scrolling performance problems in the past, although it's been a while: https://github.com/nielsbot/Profiler (yes, I'm plugging my own code :-)
Re:FastImageCache – iOS library for quickly displaying image... by michaelmior on Monday October 21, 2013 @10:15PM (#6589431)
Yes. If you mmap a file and then try to access it and it's not already in RAM, you'll block while the bit you're trying to access is paged in.
Re:FastImageCache – iOS library for quickly displaying image... by skyebook on Monday October 21, 2013 @09:46PM (#6589332)
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.

Re:FastImageCache – iOS library for quickly displaying image... by liuliu on Monday October 21, 2013 @10:07PM (#6589397)
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 :)
Re:FastImageCache – iOS library for quickly displaying image... by skyebook on Monday October 21, 2013 @10:51PM (#6589526)
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 image... by nielsbot on Tuesday October 22, 2013 @02:12AM (#6590060)
that can work depending on how many images you have... Note also that there's a decompression hit loading PNG too.
Re:FastImageCache – iOS library for quickly displaying image... by pugz on Monday October 21, 2013 @10:17PM (#6589436)
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 image... by malkia on Monday October 21, 2013 @09:23PM (#6589269)
Wondering if there is any support for PVR compressed images(2bit/4bit)?