Benchmarking JSON vs Protobuf Performance in Java
This article benchmarks Java JSON libraries against Google Protobuf, analyzing decode/encode performance for integers, doubles, strings, objects, and lists, revealing that while Protobuf often outperforms JSON, optimized JSON libraries like DSL‑JSON can narrow the gap dramatically.
The common claim that Google Protocol Buffers (Protobuf) is dramatically faster than JSON—often quoted as "5× faster"—is examined with concrete JMH benchmarks. The author, a JSON performance expert, questions whether switching from JSON to Protobuf truly yields a ten‑fold speedup given the migration cost.
Benchmarks are run on a variety of Java serializers: Jackson (with AfterBurner), DSL‑JSON, Jsoniter, Fastjson, Protobuf, and Thrift. Test data include extreme cases (very small, medium, and very large payloads) to expose strengths and weaknesses of each format.
Integer decoding : Protobuf decodes an integer about 8× faster than Jackson (22124 ns vs 181357 ns). With ten integer fields the advantage drops to ~8.5×, still significant. DSL‑JSON’s optimized value = (value << 3) + (value << 1) + ind; implementation narrows the gap.
Integer encoding : Protobuf encodes integers roughly 3× faster than Jackson, while DSL‑JSON’s hand‑crafted number converter again reduces the difference.
Double decoding : Protobuf is about 13× faster than Jackson (92 447 ns vs 1 271 311 ns). Jsoniter’s base‑64 fallback improves speed but remains slower than Protobuf. DSL‑JSON’s custom double handling (storing as a scaled long) also helps.
Double encoding : Protobuf encodes doubles ~13× faster than Jackson. If six‑digit precision is acceptable, Jsoniter’s Base64FloatSupport.enableEncodersAndDecoders(); brings the speed within 2× of Protobuf.
Object decoding : With a single string field, Protobuf is only ~2.5× faster than Jackson; with five or ten fields the advantage shrinks to ~1.3× and ~1.2× respectively. DSL‑JSON’s hash‑based field dispatch is comparable or faster.
Object encoding : Protobuf’s advantage over Jackson is modest (~1.7×). DSL‑JSON again leads, especially when field names are short.
List handling : For integer lists Protobuf is ~3× faster than Jackson, but DSL‑JSON’s performance is close. For object lists Protobuf is ~1.3× faster than Jackson, yet DSL‑JSON remains ahead. Double arrays show Protobuf ~5× faster than Jackson, but DSL‑JSON’s pure‑Java implementation narrows the gap.
Skipping structures : Protobuf can skip unwanted fields about 5× faster than Jackson, highlighting the benefit of length‑prefixed binary formats.
Conclusion : JSON is inherently slower for numeric heavy workloads, especially double handling. Optimized JSON libraries (DSL‑JSON, Jsoniter) can reduce the performance gap to 2–4×, and in some scenarios JSON may even be competitive. However, the actual benefit of switching to Protobuf depends heavily on data characteristics; for string‑dominated payloads the gain may be negligible or even negative.
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.
High Availability Architecture
Official account for High Availability Architecture.
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.
