Improving Facebook’s performance on Android with FlatBuffers

Visit the post for more.

George Xie
9 min readintermediate
--
View Original

Overview

The article discusses how Facebook improved the performance of its Android app by adopting FlatBuffers, a data serialization format that allows for efficient storage and retrieval of data structures. It highlights the limitations of using JSON and the advantages of FlatBuffers in terms of speed, memory usage, and architectural simplicity.

What You'll Learn

1

How to use FlatBuffers for efficient data storage in Android applications

2

Why FlatBuffers outperform JSON in mobile app performance

3

How to implement mutation tracking in FlatBuffers

Prerequisites & Requirements

  • Understanding of data serialization formats
  • Familiarity with FlatBuffers library(optional)

Key Questions Answered

How does FlatBuffers improve performance over JSON in Android apps?
FlatBuffers improves performance by allowing direct access to data without deserialization, reducing load times from 35 ms to 4 ms per story. Additionally, it minimizes memory allocations by 75%, leading to a more responsive UI and reduced cold start times by 10-15%.
What are the main advantages of using FlatBuffers for data storage?
FlatBuffers offers advantages such as reduced parsing time, lower memory usage, and direct access to data components. This eliminates the need for intermediate object creation, thus enhancing the performance of Android applications significantly.
How can mutations be handled in FlatBuffers?
Mutations in FlatBuffers are handled by tracking changes alongside the original data structure. This allows for updates without needing to redownload entire objects, improving efficiency in reflecting changes like friendship status updates.

Key Statistics & Figures

Story load time from disk cache
reduced from 35 ms to 4 ms
This metric illustrates the significant performance improvement achieved by using FlatBuffers.
Transient memory allocations
reduced by 75 percent
This reduction alleviates pressure on the Java garbage collector, enhancing application responsiveness.
Cold start time improvement
10-15 percent
This improvement contributes to a better user experience by reducing the time it takes for the app to become usable.
Storage size reduction
15 percent
This reduction helps in optimizing the app's footprint on devices.

Technologies & Tools

Data Serialization
Flatbuffers
Used for efficient data storage and retrieval in the Facebook Android app.

Key Actionable Insights

1
Adopt FlatBuffers for data serialization in your Android applications to enhance performance.
Using FlatBuffers can significantly reduce load times and memory usage, making your app more responsive, especially important for mobile environments with limited resources.
2
Implement mutation tracking alongside FlatBuffers to efficiently manage data updates.
This approach allows for localized updates without the overhead of redownloading entire data structures, which is crucial for maintaining performance in dynamic applications.
3
Transition from JSON to FlatBuffers to streamline your data handling architecture.
FlatBuffers can simplify the interaction between your storage and UI layers, reducing complexity and improving the overall architecture of your application.

Common Pitfalls

1
Over-reliance on JSON for data storage can lead to performance issues.
JSON parsing can be slow and memory-intensive, which is particularly problematic in mobile applications where performance is critical.
2
Neglecting to implement mutation tracking can lead to inefficient data updates.
Without mutation tracking, developers may need to redownload entire data structures for minor updates, which can degrade performance.

Related Concepts

Data Serialization
Mobile Performance Optimization
Flatbuffers Architecture
Mutation Tracking