Benchmarking JSON vs Protobuf Performance in Java: Decoding and Encoding Speed Comparison
This article presents a comprehensive Java benchmark that compares JSON libraries (Jackson, Fastjson, DSL‑JSON, Jsoniter, Thrift) with Google Protocol Buffers across various data types and structures, revealing where Protobuf truly outperforms JSON and where modern JSON parsers narrow the gap.
The author questions the common belief that Protocol Buffers (Protobuf) is always dramatically faster than JSON, and designs a series of JMH benchmarks to compare several popular Java JSON libraries (Jackson, Fastjson, DSL‑JSON, Jsoniter, Thrift) against Protobuf and Thrift across multiple scenarios.
Methodology : Benchmarks cover decoding and encoding of integers, doubles, objects, lists, arrays, and long strings, as well as skipping structures. Test data includes extreme cases (single field, 5 fields, 10 fields) and both packed and unpacked repeated fields. Source code snippets are kept intact, e.g., value = (value << 3) + (value << 1) + ind; for integer decoding, and Base64FloatSupport.enableEncodersAndDecoders(); for double handling.
Key Findings :
Protobuf decodes a single integer up to 8× faster than Jackson, but the advantage drops to ~1.2× when handling five or ten fields.
For double values, Protobuf is roughly 13× faster than Jackson, while DSL‑JSON and Jsoniter close the gap to 2‑3× with aggressive optimizations.
Object binding speed is comparable across formats; Protobuf’s tag‑based dispatch offers only a modest benefit over hash‑based JSON field matching.
Encoding performance shows Protobuf can be up to 15× faster for double arrays, but DSL‑JSON often outperforms Protobuf for other structures.
Skipping large strings is where Protobuf shines (≈5× faster than Jackson) because JSON must scan the entire payload.
Conclusion : JSON libraries have improved dramatically; for many real‑world workloads the speed difference between JSON and Protobuf is modest, and DSL‑JSON frequently surpasses Protobuf. Switching to Protobuf is only justified when the workload heavily involves numeric fields (especially doubles) or when constant‑time skipping of large structures is critical.
Additional resources and links to the benchmark code are provided throughout the article.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
