Instagram Jul 18, 2023

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

Critical Insight

Instagram eliminated JSON parsing bottlenecks by auto-generating stream parsers, delivering faster News feed loads without the memory overhead of traditional approaches.

The benchmark results show just how much faster subsequent parsing iterations became compared to ObjectMapper.

About This Article

Problem

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.

Solution

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.

Impact

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.