Fraser Speirs Cocoa and Photos

Posted
10 October 2008 @ 10am

Tagged
Programming, Tech

Add:     

Exposure 1.1 post-mortem

[Preamble: if you don't have Exposure, here are App Store links to Exposure (free) and Exposure Premium ($9.99)]

Exposure 1.1 is now available on the App Store. This is the first serious feature update for Exposure, and it includes a ton of work under the hood which is succinctly summarised in the release notes as:

Thumbnails now load much faster.

Exposure started life as a prototype desktop application (hereinafter referred to as “the desktop app”) . I restarted the iPhone development from scratch and didn’t use any code from the desktop app for 1.0. In Exposure 1.0, I was worried about falling foul of Apple’s instruction that iPhone apps should not be “bandwidth hogs”, so I took a very conservative approach to network traffic: one request at a time and no preloading.

With some more experience under my belt, I realised that the crushing problem with wireless networking (whether EDGE or 3G) was latency, not bandwidth per se. Doing “one request at a time”, particularly for small objects like Flickr’s 75px thumbnails, means that you pay the high time-cost of latency once for every object you load.

In Exposure 1.1, I ported the image downloading code from the desktop app to the phone. This code provides multiple queues, a priority scheduler and highly parallel downloading. Exposure 1.1 now runs 15 thumbnail requests in parallel, so you pay the latency cost once and then start to see several images load.

Caching

Exposure 1.1 caches thumbnails in an SQLite database on the phone. I originally wrote a filesystem-based image cache which worked, but had a few pathological code paths. The worst offender was the time it took to calculate the current size of the cache, for which I had to walk the file hierarchy and sum the size of each file. After hearing Dr. Richard Hipp’s talk on SQLite at C4 it was clear what I had to do. I ripped out the filesystem cache and, with some help and code from Ian Baird, I had a faster and more elegant cache in far fewer lines of code in just a couple of days.

Near Me

Near Me now has a lot more control over the results of the search. In Exposure 1.0, the results were taken from a five mile radius and sorted by ascending distance from your location. This was usually OK, but produced some bad results in situations where a lot of uninteresting pictures were taken near your location. The canonical example is if you were in a restaurant or pub district of a city. In such an area, you would find a lot of photos of people you didn’t know at parties appearing at the top of the search and pushing more interesting photos down the list.

In Exposure 1.1, you firstly have control over the search radius, from 1 mile up to 20 miles. This helps in situations where you’re in a place that’s either very densely-tagged (where you might want to narrow the radius) or sparsely-tagged (where a radius wider than 5 miles might get you something). Exposure 1.1 also lets you use distance, interestingness or date as the field to sort on. For interestingness and date, you can choose ascending or descending sort. The Flickr API only returns ascending distance, so sort direction is ignored if you’re sorting on distance.

My favourite arrangement is a search radius of 2-3 miles, sorted by descending interestingess (i.e. most interesting first). In areas that you frequent a lot, you might want to choose descending-date sorting to show you the newest photos near your house. Lots of good options.

Finally, I should say that distances are now localised to the unit of measurement in use in your locale. I will further apologise to my fellow Brits that iPhone OS thinks we use metres and kilometres for distance. Distances are currently only displayed in the row view and not the thumbnail view.

Interface

There were a number of changes to the interface in Exposure 1.1. Most obvious amongst them is that Exposure now shows thumbnails in a 4-column grid instead of the single-image rows that 1.0 had. The 1.0 interface is still there, and can be selected in the new Settings view. It’s not obvious but, if you double tap a thumbnail, you’ll go to the info view instead of the full-screen view.

Onwards!

Not every feature made it into Exposure 1.1. In particular, uploading isn’t there yet. I decided to play it safe with this release and just do two or three highly disruptive code changes instead of four or five. I also didn’t want to delay getting the new downloader and cache into the hands of users. Performance is a feature, and I think that this new version makes using Exposure a significantly more pleasant experience.


23 Comments

Posted by
Jim the Red
10 October 2008 @ 11am

Been playing with the new version and am loving the improvements.

Would be great if i could set location aware preferences of the ‘Near Me’ function so that i don’t have to keep adjusting it depending on my location.

That way while i’m walking round Glasgow City Centre i could have stuff sorted by intrestingness within 1 mile.

Then while i’m at home maybe date ascending within one mile.

Then while i’m wandering round the Highlands, location within 20 miles.


Posted by
fraserspeirs
10 October 2008 @ 11am

Fascinating idea, and one I never thought of: location-aware settings. Putting that on the list right now.


Posted by
Geof F. Morris
10 October 2008 @ 11am

I’ve downloaded it and played around … VERY nice, Fraser, and a fantastic update.


Posted by
Travis Isaacs
10 October 2008 @ 2pm

I’m anxious to try out v1.1.

I personally thought of Exposure as a replacement for syncing photos to my phone (because support for syncing Aperture library sucks). But Honestly, I stopped using Exposure when the new m.flickr.com was released, it’s that good.

As you mentioned before, the speed of Exposure was constantly a problem, it always felt like it was waiting to load something whether I needed it or not. The “infinite paging” is a very useful pattern in most contexts, but not on a mobile device where bandwidth is limited and latency is high. M.flickr.com has traditional paging and it works much better in my opinion.

Other minor things prompted me to go back to m.flickr.com, such as being able to see a photo’s exif data (well, sorta, it’s a limited set), and being able to hop to one of my contact’s photostream (maybe you can do it in exposure, but I can’t figure it out).

I also realize that you can’t please everyone, but I’m really pulling for this application!


Posted by
fraserspeirs
10 October 2008 @ 2pm

@Travis The new m.flickr is great. I hope to add value by doing the thing that web apps universally suck at: integrating with the platform, the best example being Near Me.

Exposure doesn’t currently behave differently according to the networking setup. The design in Exposure 1.1 is great on Wi-Fi and OK on 3G, but might still be a little heavyweight for EDGE.

To see your contacts’ photostreams, go to the Contacts tab, tap All in the control at the top, then tap a contact’s name. That view is currently limited to the most recent 100 images.

Good idea to provide EXIF display. Noted!


Posted by
Michael Mistretta
10 October 2008 @ 3pm

Very nice update. I do prefer Exposure to m.flickr.com, as it feels more native. That said, there are a couple rough areas of Exposure. Recent Activity for example, is excellently executed on m.flickr.com. Also, comment view needs avatars, and EXIF information would be nice. I’m sure Exposure will continue to be polished over time.

Keep up the good work!


Posted by
Jesse David Hollington
10 October 2008 @ 3pm

Great update, and definitely some nice improvements. The ability to control the “Near Me” results was one of the things that I clearly preferred in another app, so it’s nice to see it living in Exposure now, since I’ve always preferred the general polish and UI of Exposure over any of the other apps out there.

I seem to recall that somewhere in the v1.0.x stream there was the ability to view a map for a geo-tagged picture, or am I imaginging that? If it was there, then v1.1 seems to have taken it away, if not then it would still be a nice addition to see in the next rev.


Posted by
Allan Crain
10 October 2008 @ 3pm

Any chance of adding support for sliding from one picture to the next like the built-in photos app and the Facebook photo app? It’s a really nice tactile way to navigate pictures that doesn’t require keeping the little navigation controls on the screen to obscure the picture. Especially nice if you could preload the images on either side of the current one.


Posted by
fraserspeirs
10 October 2008 @ 3pm

@Allan Crain Yes, absolutely. It’s in my development version now. I wanted to make the experience as smooth as possible, which depended on getting this much better downloading code into Exposure first. Now that I can pull images in parallel and faster, the swipe experience will be (is) much better.


Posted by
Steven Fisher
10 October 2008 @ 3pm

It’s funny that SQLite still seems to be one of the best kept secrets in programming.


Posted by
John Muir
10 October 2008 @ 4pm

Fraser: am I just being dumb, or is it currently impossible to pan around a photo in Exposure using multi-touch? When I activate a shot, all I can do is look dead centre when zoomed in.


Posted by
Yann
10 October 2008 @ 4pm

This new version is speedy which I love, but I found a truckload of minor bugs :)

1. Problems with landscape mode
- Switch to one of the grid views
- View a picture
- Switch to landscape mode
- Hit the return button
- You either get an interface where the ad takes all the with and all the picture are jammed to the left, or if you came to the full screen viewer using this sequence: contacts -> all -> “one of your contacts” then everything is jammed onto the left side and is a high as a vertical view

2. Coming back from landscape view is bugged
- After experiencing the less than nominal experience described above switch back to portrait mode
- The ad on top is compressed in a strange way to fit horizontally

3. Location is not refreshed when in the “near me” view
- You used the location service in a different place than the one you’re in now.
- Old location is displayed at the top
- Pictured starts to pour in but they’re close to where you used to be
- Background location refresh finishes
- View refreshes with pictures actually close to where you really are
- Location bar at the top still shows the old location

Hope all this helps you make an even better 1.1.1 version!


Posted by
fraserspeirs
10 October 2008 @ 4pm

@John Muir The full-screen view loads the 500px size from Flickr, so there’s not much more detail to see, even if you could multi-touch zoom it. Currently a double-tap will switch the view between size-to-fit and size-to-fill. Definitely want to improve this.

@Yann Thanks for the report. Will look into it.


Posted by
John Muir
10 October 2008 @ 4pm

Fair enough. Thanks for the update!


Posted by
Paul
10 October 2008 @ 5pm

Is there any way to display groups that you’re a part of? I’ve never looked at Flickr’s API, so I don’t know if that’s even possible, but that’s one feature that would really make it for me!


Posted by
Nick
10 October 2008 @ 5pm

When we developed the Style.com app we first built a complex NSURLConnection loading queue for thumbnails and such, since as you say, we wanted to be careful not to overwhelm the iPhone with thumbnail requests. It was slow, and we noticed that it was making a new HTTP request to the server for each thumbnail instead of using keepalive.

So we mulled around for a bit and thought, you know, Apple probably designed the loading system expecting the average programmer to just lazily make requests without a second thought instead of making a complex queuing system, since this is a very common situation.

So we rewrote it to just make ALL the (visible) thumbnail requests simultaneously - i.e. creating dozens of NSURLConnections and letting them work their magic. Turns out the system queues them and executes them in parallel to the tune of about 4 (IIRC) at a time. And lo, the loading was much much faster.


Posted by
Daniel
10 October 2008 @ 6pm

Really fantastic improvements; I really shied away from using 1.0 because I’m not regularly on WiFi and it just took too long. The preloading and SQLite caching definitely fixes that right up!

I am curious – would you be able to implement a Commenting system similar to the new Facebook 2.0? I just went through and tried out adding a comment to a contact’s photo – it worked fine, but it seems like there’s perhaps an additional step or two that you could eliminate. I love how Facebook’s item comments are basically a click away, and the “text bubble” idea just feels so natural for it too.

Thanks for all your work, Fraser!


Posted by
Steven Peterson
10 October 2008 @ 6pm

Are you achieving parallel downloads by spinning off new threads for NSURLConnection? I was under the impression that multiple NSURLConnections could load data in parallel. Is that not true? I’m trying to solve a similar problem.


Posted by
fraserspeirs
10 October 2008 @ 8pm

@Nick Thanks for the insights.

@Steven Peterson I’m starting the NSURLConnections on the main thread and relying on NSURLConnection’s asynchronous mode to parallelize them for me. I’m not spawning one thread per connection (at least not by hand).


Posted by
Bret
12 October 2008 @ 1am

I really like the improvements you’ve made with 1.1.

One additional feature I’d like to see is the ability to load more photos for Contacts, Featured and Near Me. Is there a reason it’s there for My Photos, but not for the others?


Posted by
fraserspeirs
12 October 2008 @ 8am

@Bret No technical reason that I can remember right now, just a matter of priorities.


Posted by
Alf Watt
15 October 2008 @ 3am

This reminds me of a classic networking rant from Stuart Cheshire: “It’s the Latency, Stupid”

http://rescomp.stanford.edu/~cheshire/rants/Latency.html


Posted by
VirtualWolf
15 October 2008 @ 5am

One thing that annoys me about Mobile Fotos is that when you upload a photo and tell it to include your current location, it’s actually where you are at the point of /upload/, not where the photo itself was taken. If you’re in a moving vehicle, the difference between where the photo was taken and where you are at that point can be very large!

If/when you add photo uploading, if it’s possible to just include the geotagging data from the photo itself rather than the “Current location”, that would be excellent. :)