NewImageFacebook employee Jonathan Dann has written a blog post detailing how the company's iOS engineering team designed earlier Facebook for iPhone apps and the extensive coding that was required to rewrite the new Facebook 5.0 app.

The post is a bit technical in parts, but is worth a read for developers and others interested in how one of the most popular iPhone apps gets made.

An excerpt:

One of the biggest advantages we've gained from building on native iOS has been the ability to make the app fast. Now, when you scroll through your news feed on the new Facebook for iOS, you'll notice that it feels much faster than before. One way we have achieved this is by re-balancing where we perform certain tasks. For example, in iOS, the main thread drives the UI and handles touch events, so the more work we do on the main thread, the slower the app feels. Instead, we take care to perform computationally expensive tasks in the background. This means all our networking activity, JSON parsing, NSManagedObject creation, and saving to disk never touches the main thread.

To give another example, we use Core Text to lay out many of our strings, but layout calculations can quickly become a bottleneck. With our new iOS app, when we download new content, we asynchronously calculate the sizes for all these strings, cache our CTFramesetters (which can be expensive to create), and then use all these calculations later when we present the story into our UITableView.

Finally, when you start Facebook for iOS, you want to see your news feed, not a loading spinner. To provide the best experience possible, we now show previously-cached content immediately. But this introduces a new problem: If you have a lot of stories in your news feed, UITableView throws a small spanner in the works by calling the delegate method -tableView:heightForRowAtIndexPath: for each story in your news feed in order to work out how tall to make its scrollbar. This would result in the app loading all the story data from disk and calculating the entire story layout solely to return the height of the story, meaning startup would get progressively slower as you accumulate more stories.

The solution to this particular problem has two main parts. Firstly, when we do our initial asynchronous layout calculations, we also store the height of the story in Core Data. In doing so, we completely avoid layout calculation in -tableView:heightForRowAtIndexPath:. Secondly, we've split up our "story" model object. We only fetch the story heights (and a few other things) from disk on startup. Later, we fetch the rest of the story data, and any more layout calculations we have to do are all performed asynchronously.

Top Rated Comments

JangoFett124 Avatar
152 months ago
Hate to see if they had to work on a game or some other app that really required good coding skills.

I guess making an app to download cat pics and "I'm going to bed now!" messages was tough work.



Michael

Do you have programming experience?
Score: 19 Votes (Like | Disagree)
Pakaku Avatar
152 months ago
It's marginally better. Completely rewritten, huh? So instead of making actual improvements on the UI in the process, they kept the same limited capabilities and just made the app start up a little faster.

Still no way to share posts.
I don't use the facebook app, but I'm pretty sure I'd like a decent, usable app that's missing a few features, rather than a terrible, laggy app.
Score: 13 Votes (Like | Disagree)
Tinmania Avatar
152 months ago
Hate to see if they had to work on a game or some other app that really required good coding skills.

I guess making an app to download cat pics and "I'm going to bed now!" messages was tough work.



Michael
Score: 13 Votes (Like | Disagree)
JangoFett124 Avatar
152 months ago
Nah.... just how I have earned my living for the last 11 years. That's all lol.

Sorry, it's just that your comment makes it seem like you have never coded anything of quality. Just because it can display cat pictures doesn't make it trivial. I would expect anyone with experience to respect the work that went into this app, especially after reading the linked article.
Score: 9 Votes (Like | Disagree)
TylerL Avatar
152 months ago
It's always great to see real-world hard-won experience doled out like this.

To those mad there aren't more changes, rebuilding is hard. New features are hard too. Don't do both at once. Rebuilding makes future changes easier.
Patience. Mobile users barely make Facebook money anyway.
Score: 7 Votes (Like | Disagree)
slrandall Avatar
152 months ago
Hate to see if they had to work on a game or some other app that really required good coding skills.

I guess making an app to download cat pics and "I'm going to bed now!" messages was tough work.



Michael

Never coded before, have you? Games are difficult but nowhere near the most challenging.
Score: 6 Votes (Like | Disagree)

Popular Stories

maxresdefault

Apple Announces 'Let Loose' Event on May 7 Amid Rumors of New iPads

Tuesday April 23, 2024 7:11 am PDT by
Apple has announced it will be holding a special event on Tuesday, May 7 at 7 a.m. Pacific Time (10 a.m. Eastern Time), with a live stream to be available on Apple.com and on YouTube as usual. The event invitation has a tagline of "Let Loose" and shows an artistic render of an Apple Pencil, suggesting that iPads will be a focus of the event. Subscribe to the MacRumors YouTube channel for more ...
Apple Silicon AI Optimized Feature Siri

Apple Releases Open Source AI Models That Run On-Device

Wednesday April 24, 2024 3:39 pm PDT by
Apple today released several open source large language models (LLMs) that are designed to run on-device rather than through cloud servers. Called OpenELM (Open-source Efficient Language Models), the LLMs are available on the Hugging Face Hub, a community for sharing AI code. As outlined in a white paper [PDF], there are eight total OpenELM models, four of which were pre-trained using the...
iOS 18 Siri Integrated Feature

iOS 18 Rumored to Add These 10 New Features to Your iPhone

Wednesday April 24, 2024 2:05 pm PDT by
Apple is set to unveil iOS 18 during its WWDC keynote on June 10, so the software update is a little over six weeks away from being announced. Below, we recap rumored features and changes planned for the iPhone with iOS 18. iOS 18 will reportedly be the "biggest" update in the iPhone's history, with new ChatGPT-inspired generative AI features, a more customizable Home Screen, and much more....
Apple Vision Pro Dual Loop Band Orange Feature 2

Apple Cuts Vision Pro Shipments as Demand Falls 'Sharply Beyond Expectations'

Tuesday April 23, 2024 9:44 am PDT by
Apple has dropped the number of Vision Pro units that it plans to ship in 2024, going from an expected 700 to 800k units to just 400k to 450k units, according to Apple analyst Ming-Chi Kuo. Orders have been scaled back before the Vision Pro has launched in markets outside of the United States, which Kuo says is a sign that demand in the U.S. has "fallen sharply beyond expectations." As a...
iPad And Calculator App Feature 1

Apple Finally Plans to Release a Calculator App for iPad Later This Year

Tuesday April 23, 2024 9:08 am PDT by
Apple is finally planning a Calculator app for the iPad, over 14 years after launching the device, according to a source familiar with the matter. iPadOS 18 will include a built-in Calculator app for all iPad models that are compatible with the software update, which is expected to be unveiled during the opening keynote of Apple's annual developers conference WWDC on June 10. AppleInsider...