Facebook uses FlatBuffers on one billion Android devices

· flatbuffers facebook java android

This is a post in an ongoing series on FlatBuffers.

In July, Facebook announced that they use FlatBuffers in their Android apps. In particular, they now use FlatBuffers instead of JSON for client-server communication.

You should go check out the article: it has diagrams showing how FlatBuffers organizes data in memory, and gives insight into the decision-making process that led Facebook to make such a big change.

Benefits

Here are some of the benefits they mention:

Smoother UI

With JSON, the time to parse a Facebook news story was longer than the frame refresh interval. This means that users could experience visual stutter as they scrolled the news feed. FlatBuffers helps to eliminate scroll stutter by loading data faster. (If you’re curious: the frame refresh interval is 16.6ms, JSON was getting parsed in 34ms, and FlatBuffers brought that down to 3ms.)

Faster startup

At app startup, the JSON library required 100-200ms to build a parser. FlatBuffers generates a parser at compile-time, eliminating this delay.

Less pressure on the garbage collector

Using JSON required many short-lived memory allocations, which placed a lot of pressure on the Java garbage collector. FlatBuffers brings transient allocations down to zero.

Simpler app architecture

After switching to FlatBuffers, Facebook found that they could eliminate some internal caching layers.

Get involved

Since Facebook trusts FlatBuffers for serialization on over 1 billion devices, maybe you’d like to give it a try, too? :-)

FlatBuffers is available for C++, C#, Go, Java, Javascript, and Python. If you’d like to contribute or use it, head over to the homepage at https://google.github.io/flatbuffers/ to get started!

About the author

I'm Robert Winslow, a consulting engineer. I help teams launch great products: Learn more.