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
154 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
154 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
154 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
154 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
154 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
154 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

ios 18 button bulge

iOS 18 Adds Pop-Out Bezel Animation When Pressing iPhone Buttons

Tuesday June 11, 2024 10:40 am PDT by
iOS 18 includes a small but interesting change for the buttons on the iPhone, adding more of a visual element when changing volume, activating the Action button, or locking the screen. When you press an iPhone button in iOS 18, the display bezel bulges outward slightly. This feature is available for the volume buttons, Action button and the power button, and it will also likely be used for...
iOS 18 Mock iPhone 16 Feature Gray

Revealed: iOS 18 Works With These iPhone Models

Monday June 10, 2024 3:57 am PDT by
iOS 18 will be compatible with the same iPhone models as iOS 17, according to a post on X today from a private account with a proven track record of sharing build numbers for upcoming iOS updates. iOS 18 will be compatible with the iPhone XR, and hence also the iPhone XS and iPhone XS Max models with the same A12 Bionic chip, but older iPhone models will miss out. Here is the full...
Next Gen CarPlay WWDC24 1

Apple Provides Updated Look at Next-Generation CarPlay at WWDC 2024

Monday June 10, 2024 7:11 pm PDT by
Apple today shared a few WWDC 2024 coding sessions related to its upcoming next-generation CarPlay system ahead of its launch later this year. The sessions include lots of updated next-generation CarPlay images, with one revealing new Vehicle, Media, and Climate apps in action for the first time. MacRumors previously discovered evidence of these apps in the iOS 17.4 beta. Next-generation...
ios 18 tile summary

Apple Announces iOS 18 With New Customization Features, Redesigned Photos App, and More

Monday June 10, 2024 10:17 am PDT by
Apple today previewed iOS 18, the next major update to the operating system for the iPhone, with new customization features, a redesigned Photos app, and more. iOS 18 features new customization tools for the Home Screen. App icons now feature Dark Mode and users can tint them with a color to create a unique look. Apps can also now be placed anywhere on the Home Screen freely. The Control...
sequoia

macOS Sequoia and iPadOS 18 Drop Support for These Macs and iPads

Monday June 10, 2024 4:13 pm PDT by
macOS Sequoia is still compatible with several Intel-based Macs, but it does drop support for 2018 and 2019 models of the MacBook Air. macOS Sequoia is compatible with the following Macs, according to Apple: MacBook Pro: 2018 and later MacBook Air: 2020 and later Mac mini: 2018 and later iMac: 2019 and later iMac Pro: 2017 Mac Studio: 2022 and later Mac Pro: 2019 and later The...
maxresdefault

Everything Apple Announced at WWDC 2024 in Nine Minutes

Monday June 10, 2024 7:59 pm PDT by
Apple crammed an overwhelming number of new features into its WWDC 2024 keynote event, introducing Apple Intelligence, iOS 18, iPadOS 18, macOS Sequoia, visionOS 2, watchOS 11, and tvOS 18. It was hard to keep up with everything that Apple highlighted, so we did a video of all of the new additions you won't want to miss. Subscribe to the MacRumors YouTube channel for more videos. We've also...
iOS 18 Siri Integrated Feature

Massive iPhone Upgrade Coming This Week But These Devices Will Miss Out

Sunday June 9, 2024 1:25 pm PDT by
Apple is planning a major AI overhaul in iOS 18, with a feature set it is referring to as "Apple Intelligence." However, these new features will not work on older iPhones, even if they do appear on the new operating system's device compatibility list. Apple's initial AI roadmap for iOS 18 is said to come in two parts: Basic AI features that will be processed on-device, and more advanced...