Fast Auto-Generated Streaming JSON Parsing for Android
Article Summary
Instagram's Android app had a JSON parsing problem that was killing their News feed performance. Traditional solutions weren't cutting it.
The Instagram engineering team built ig-json-parser, a compile-time annotation processor that auto-generates streaming JSON parsers for Android. They open-sourced it in 2015 after seeing massive performance gains.
Key Takeaways
- Jackson ObjectMapper caused significant startup penalties and memory pressure
- Auto-generated stream parsing eliminates handwritten boilerplate code
- Cold start parsing improved dramatically with zero ongoing memory footprint
- JSR-269 annotation processor generates customizable parsing code at compile time
Instagram eliminated JSON parsing bottlenecks by auto-generating stream parsers, delivering faster News feed loads without the memory overhead of traditional approaches.
About This Article
Jackson ObjectMapper had a rough start. The first serialization pass hit it with heavy penalties and allocated way too much memory, which put pressure on the garbage collector. Even after operations finished, it held onto a large memory footprint.
Instagram Engineering built ig-json-parser, a JSR-269 annotation processor that generates stream parsing code from annotated model classes. This eliminated the need to write repetitive parsing code by hand, and developers could still customize behavior through pluggable code snippets.
In cold start benchmarks, the auto-generated parser was much faster than Jackson ObjectMapper. The performance gap closed on later parsing runs, and there was no ongoing memory overhead to worry about.