Home / Companies / Cockroach Labs / Blog / Post Details
Content Deep Dive

High-performance JSON parsing in Go

Blog post from Cockroach Labs

Post Details
Company
Date Published
Author
Yevgeniy Miretskiy
Word Count
2,860
Language
English
Hacker News Points
18
Summary

CockroachDB's exploration into optimizing JSON parser performance in Go reveals significant speed improvements by transitioning from the standard Go `encoding/json` library to the `jsoniter` library, and ultimately, a customized fork of the high-performance `pkg/json` library. The initial inefficiency of the ParseJSON function, which used a two-phase parsing approach, prompted benchmarking to understand its shortcomings, particularly in memory allocation. The switch to `jsoniter` resulted in substantial speed gains but revealed suboptimal allocation behavior with escaped characters. Further enhancement was achieved by adopting and modifying `pkg/json`, achieving over 1GB/s throughput and improved allocation efficiency. This project underscores the importance of careful library selection and API design in achieving high performance, while also benefiting from Cockroach Labs' "Flex Friday" policy, allowing engineers to explore such optimizations.