Skip to content

Performance testing of serialization and deserialization of Java JSON libraries

License

Notifications You must be signed in to change notification settings

lgzarturo/java-json-benchmark

 
 

Repository files navigation

Build Status

Benchmark of Java JSON libraries

Purpose

This project benchmarks the throughput performance of a variety of Java Json libraries using JMH. It covers the following libraries:

When available, both databinding and 'stream' (custom packing and unpacking) implementations are tested. Two different kinds of models are evaluated with payloads of 1, 10, 100 and 1000 KB size:

  • Users: uses primitive types, String, List and simple POJOs; and
  • Clients: adds arrays, enum, UUID, LocalDate

This benchmark is written to:

  • randomly generate payloads upon static loading of the JVM/benchmark; the seed is also shared across runs
  • read data from RAM
  • write data to reusable output streams (when possible); this reduces allocation pressure
  • consume all output streams; to avoid dead code elimination optimization

Not evaluated are: RAM utilization, compression, payloads > 1 MB.

Results

The benchmarks are written with JMH and for Java 8.

The results here-below were computed on November the 27th, 2021 with the following libraries and versions:

Library Version
jackson 2.13.0
genson 1.6
fastjson 1.2.78
gson 2.8.9
org.json 20210307
javax-json 1.1.4
json-io 4.13.0
flexjson 3.3
boon 0.34
json-smart 2.4.7
johnzon 1.2.15
logansquare 1.3.7
dsl-json 1.9.9
simplejson 1.1.1
nanojson 1.7
jodd json 6.0.3
moshi 1.12.0
tapestry 5.7.3
jsoniter 0.9.23
minimal-json 0.9.5
mjson 1.4.1
underscore 1.71
purejson 1.0.1
yasson 1.0.9

All graphs and sheets are available in this google doc.

Raw JMH results are available here

Users model

Uses: primitive types, String, List and simple POJOs

Deserialization performance json deserialization performance for primitive types, String, List and simple POJOs

Serialization performance json serialization performance for primitive types, String, List and simple POJOs

Clients model

Uses: primitive types, String, List and simple POJOs, arrays, enum, UUID, LocalDate

Note: fewer libraries are tested with this model due to lack of support for some of the evaluated types.

Deserialization performance json deserialization performance for primitive types, String, List and simple POJOs, arrays, enum, UUID, LocalDate

Serialization performance json serialization performance for primitive types, String, List and simple POJOs, arrays, enum, UUID, LocalDate

Benchmark configuration

Tests were run on an Amazon EC2 c5.xlarge (4 vCPU, 8 GiB RAM)

JMH info:

# JMH version: 1.33
# VM version: JDK 1.8.0_302, OpenJDK 64-Bit Server VM, 25.302-b08
# VM invoker: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64/jre/bin/java
# VM options: -XX:+AggressiveOpts -Xms2g -Xmx2g
# Blackhole mode: full + dont-inline hint (default, use -Djmh.blackhole.autoDetect=true to auto-detect)
# Warmup: 5 iterations, 10 s each
# Measurement: 10 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 16 threads, will synchronize iterations
# Benchmark mode: Throughput, ops/time

Run

By default, running ./run ser (./run deser respectively) will run all -- stream and databind -- serialization (deserialization respectively) benchmarks with 1 KB payloads of Users.

You can also specificy which libs, apis, payload-sizes and number of iterations (and more) you want to run. For example:

./run deser --apis stream --libs genson,jackson
./run ser --apis databind,stream --libs jackson
./run deser --apis stream --libs dsljson,jackson --size 10 --datatype users

Type ./run help ser or ./run help deser to print help for those commands.

If you wish to run all benchmarks used to generate the reports above, you can run ./run-everything. This will take several hours to complete, so be patient.

Contribute

Any help to improve the existing benchmarks or write ones for other libraries is welcome.

Adding a JSON library to the benchmark requires little work and you can find numerous examples in the commit history. For instance:

Pull requests are welcome.

About

Performance testing of serialization and deserialization of Java JSON libraries

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 97.3%
  • Shell 1.2%
  • Python 1.1%
  • Other 0.4%