The evolution of Facebook’s iOS app architecture

Facebook for iOS (FBiOS) is the oldest mobile codebase at Meta. Since the app was rewritten in 2012, it has been worked on by thousands of engineers and shipped to billions of users, and it can sup…

Dustin Shahidehpour
14 min readadvanced
--
View Original

Overview

The article discusses the evolution of Facebook's iOS app architecture over the past decade, highlighting significant architectural changes, challenges faced, and the introduction of custom frameworks and tools. It emphasizes the balance between user experience and developer efficiency, detailing the transition from traditional iOS practices to a more modular and dynamic approach.

What You'll Learn

1

How to implement a custom UI framework inspired by React for iOS applications

2

Why using dynamic libraries can improve app startup performance

3

How to leverage code generation to streamline development processes

4

When to transition from traditional iOS development practices to modular architectures

Prerequisites & Requirements

  • Understanding of iOS app architecture and development practices
  • Familiarity with dynamic libraries and build systems like Buck(optional)

Key Questions Answered

What architectural changes did Facebook implement in its iOS app over the years?
Facebook's iOS app architecture evolved significantly, introducing custom frameworks like ComponentKit, dynamic libraries for improved startup performance, and a plugin system powered by Buck. These changes were driven by the need to enhance user experience while managing a growing codebase and number of contributors.
How did the introduction of dynamic libraries impact the Facebook iOS app?
The introduction of dynamic libraries allowed Facebook to reduce the app's startup time by moving non-essential code out of the main binary. This modular approach enabled lazy loading of features, which kept the app responsive and improved overall performance.
Why did Facebook shift from C++ to Swift in its iOS app development?
Facebook shifted from C++ to Swift to align with Apple's evolving SDKs and to take advantage of Swift's modern features. This transition aimed to improve developer efficiency and reduce code bloat caused by interoperability issues between C++ and Swift.
What are the benefits of using a plugin system in the Facebook iOS app?
The plugin system allows for better code organization and reusability across different apps within Meta. It reduces runtime errors by providing build-time warnings and facilitates easier integration of new features without disrupting the core codebase.

Key Statistics & Figures

Performance improvement after migrating News Feed to a new UI framework
50 percent
This improvement was observed after the implementation of a declarative UI and a new data model.
Startup performance degradation in 2015
nearly 30 seconds
This slowdown risked the app being killed by the phone's OS due to excessive startup time.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Frontend
Componentkit
A custom UI framework inspired by React, used for building native UIs in Facebook.
Build System
Buck
Meta's open-source build system used for managing dependencies and improving build efficiency.
Programming Language
Swift
Adopted to align with Apple's SDK and improve developer efficiency.

Key Actionable Insights

1
Implementing a modular architecture using dynamic libraries can significantly enhance app performance.
By adopting dynamic libraries, developers can ensure that only necessary code is loaded at startup, which minimizes the app's launch time and improves user experience.
2
Transitioning to a plugin-based system can streamline development and reduce runtime errors.
A plugin system enables teams to work independently on features while ensuring that dependencies are managed at build time, leading to a more robust and maintainable codebase.
3
Leveraging code generation can eliminate common development bottlenecks.
By automating the generation of boilerplate code, teams can focus on building features rather than managing repetitive tasks, thus improving overall productivity.

Common Pitfalls

1
Relying too heavily on runtime checks can lead to delayed error detection and frustrating debugging experiences.
This often results in runtime failures that are difficult to trace back to their source, causing significant development delays. Transitioning to build-time checks can mitigate this issue.
2
Neglecting to update documentation when implementing new frameworks can lead to confusion among developers.
Without proper documentation, new team members may struggle to understand the architecture, leading to inefficiencies and errors in implementation.

Related Concepts

Modular Architecture In Ios Development
Dynamic Libraries And Their Impact On Performance
Code Generation Techniques In Software Engineering
Swift Vs. C++ In Modern App Development