Improving Facebook's Performance on Android with FlatBuffers
code.facebook.com
code.facebook.com
First, it uses CMake to build - for a long time Google projects had seemed pretty anti-CMake (for example using gyp, plain Makefiles or autotools) so it's nice to see them using CMake. IMO it's the best build tool, though all build tools generate various levels of hate :-)
Second it's another Google project that generates good developer docs from source code using doxygen and markdown. These docs look good on github directly (https://github.com/google/flatbuffers/tree/master/docs/sourc...) as they are markdown, and even better on the dedicated site where they have custom css.
If I were to write a C++ library, I'd definitely copy these 2 approaches.
"In last six months, we have transitioned most of Facebook on Android to use FlatBuffers as the storage format. Some performance improvement numbers include:
Story load time from disk cache is reduced from 35 ms to 4 ms per story.
Transient memory allocations are reduced by 75 percent.
Cold start time is improved by 10-15 percent.
We have reduced storage size by 15 percent."
It looks like I could update my YABE encoding which is a straight JSON binary encoding.
So they took advantage of that fact by not inflating ("flattening") the data structure using a stream.
He also mentioned Flatbuffer use in his recent at Android meetup in San Francisco and we debated it's benefits again. It has a learning curve but well worth it: https://www.youtube.com/watch?v=iQTxMkSJ1dQ
FWIW, I help maintain FlatBuffers for Go and Python. I'm happy to answer any questions I can.
The filesystem is a fantastic way to persist data for 80-90% of mobile applications.
Well Sqlite provides an extensive query language. I don't think Android's file system does.
It's incredibly hard to layout objects in memory with Java but if you don't mind the lookup hit on bytebuffers flatbuffers is a great way to structure data in the patterns you access it.
All this stuff is pretty old-hat to game dev people bit it's nice to see mainstream dev start caring a bit more about performance.
JSON parsing is a major problem on Android. When I also first ran into the 35ms parsing I thought for sure I was doing something wrong. Nope.. the latest phones can get down to 4-5ms JIT'd but still iOS is an order of magnitude or two faster which completely changes your architecture decisions.
Why this can't be integrated in to be fast & native I've never understood. It should have landed in Android a long time ago.
As far as I'm aware Dropbox uses c++ between iOS and android shared for all the model/network bits so other biggies do it.