Making News Feed nearly 50% faster on iOS

Visit the post for more.

Adam Ernst
6 min readintermediate
--
View Original

Overview

The article discusses the engineering efforts to enhance the performance of the Facebook News Feed on iOS, achieving nearly a 50% speed increase. It details the transition from Core Data to a custom model layer designed to optimize data handling and improve loading times.

What You'll Learn

1

How to optimize data models for performance in iOS applications

2

Why to consider denormalized storage in large-scale applications

3

How to implement asynchronous eventual consistency in data handling

Prerequisites & Requirements

  • Understanding of Core Data and its limitations
  • Familiarity with JSON data structures
  • Experience with Objective-C programming(optional)

Key Questions Answered

What caused the slowdown in News Feed performance on iOS?
The slowdown was attributed to the data model layer, specifically the increasing complexity and size of the Core Data database as more features were added. The time taken to create and query model objects grew longer with each release, necessitating a complete overhaul of the model layer.
How did Facebook improve the speed of News Feed on iOS?
Facebook improved the speed of News Feed by replacing Core Data with a custom model layer that prioritized immutability, denormalized storage, and asynchronous eventual consistency. This change led to nearly a 50% increase in loading speed.
What are PONSOs and how do they differ from Core Data objects?
PONSOs, or plain ol' NSObjects, are a new type of model object developed by Facebook that are immutable and designed for performance. Unlike Core Data objects, PONSOs do not require complex fetch-or-create operations, thus reducing overhead and improving speed.
What principles guided the development of the new model layer?
The new model layer was guided by three principles: immutability, denormalized storage, and asynchronous, opt-in consistency. These principles were aimed at optimizing performance and reducing complexity in data handling.

Key Statistics & Figures

Performance improvement
nearly 50%
Achieved by replacing Core Data with a custom model layer for News Feed

Technologies & Tools

Backend
Core Data
Initially used for managing data models in the Facebook iOS app
Backend
Nscoding
Used for serializing models to disk in the new model layer

Key Actionable Insights

1
Implementing a custom model layer can significantly enhance application performance, especially as the complexity of data increases.
As applications scale, relying on traditional ORM frameworks like Core Data may lead to performance bottlenecks. Transitioning to a tailored solution can mitigate these issues.
2
Prioritize immutability in data models to simplify concurrency management and improve thread safety.
By ensuring that data models are immutable, developers can avoid the complexities of locking mechanisms, leading to cleaner and more maintainable code.
3
Consider denormalized storage for applications that primarily serve as a cache for server data.
Denormalization can reduce the overhead associated with complex relationships and indexing, making data retrieval faster and more efficient.

Common Pitfalls

1
Relying too heavily on ORM frameworks like Core Data can lead to performance issues as application complexity grows.
This happens because ORM frameworks often introduce overhead that becomes significant when dealing with large datasets and complex relationships. It's crucial to assess whether the features provided by such frameworks are necessary for your application's scale.

Related Concepts

Data Modeling In Ios Applications
Performance Optimization Techniques
Asynchronous Programming In Objective-c