Java JSON Benchmark

28
Java JSON Parser Benchmarks Rick Hightower

description

Groovy JSON support and the Boon JSON parser are up to 3x to 5x faster than Jackson at parsing JSON from String and char[], and 2x to 4x faster at parsing byte[]. Groovy JSON support and Boon JSON support are also faster than Jackson at encoding JSON strings. Boon is faster than Jackson at serializing/de-serializing Java instances to/fro JSON. The core of the Boon JSON parser has been forked into Groovy 2.3 (now in Beta). In the process Boon JSON support was improved and further enhanced. Groovy and Boon JSON parsers speeds are equivalent. Groovy now has the fastest JSON parser on the JVM.

Transcript of Java JSON Benchmark

Page 1: Java JSON Benchmark

Java JSON ParserBenchmarks

Rick Hightower

Page 2: Java JSON Benchmark

• Java Boon - Benchmarks

• Boon comes with a fast JSON parser. This parser was forked / merged into Groovy 2.3. The Boon and Groovy 2.3 JSON parsers are a lot faster than mainstream JSON parsers.

• "Rick / Andrey duo spent a fair amount of time optimizing our JSON support, making Groovy 2.3’s JSON support usually faster than all the JSON libraries available in the Java ecosystem." -- Guillaume Laforge

Page 3: Java JSON Benchmark

How much faster?

Page 4: Java JSON Benchmark

Benchmark uses JMH

• JMH is what OpenJDK uses

• We used json files from json.org for parsing

Page 5: Java JSON Benchmark

Environment

• Environment

• OSX MacBook Pro, JDK 1.7, 16GB RAM and 512GB SSD drive

Page 6: Java JSON Benchmark

Summary• Jackson is consistently faster than GSON and JSONSmart.

• Boon JSON parser is faster than Jackson with Reader, reading files, byte[], and char[] and String.

• Boon is 3x to 5x faster than Jackson at parsing JSON from String and char[], and 2x to 4x faster at parsing byte[]

• Boon and Jackson speeds are much closer with InputStream based parsing. Boon is usually faster at InputStream, but the margins are much smaller.

• Boon and Jackson are close at handling InputStream if the JSON stream is small. Once the JSON stream gets over 1KB to 2KB, Boon wins consistently.

• Boon is faster at encoding JSON strings, and serializing/de-serializing Java instances to/from JSON than Jackson.

Page 7: Java JSON Benchmark

FAQ 1

• Why don't you test GSON and JSONSmart?Jackson is faster than GSON and JSONSmart. We have tests for all four. We only included the tests for Jackson because Jackson is faster than the other two. Anyone can download the benchmark and run all of the tests.

Page 8: Java JSON Benchmark

FAQ 2

• Why don't you test Jackson AST?

• We do. We see no real difference between readTree and readValue. We left out AST because it is redundant. The tests are still there and easy to run. AST +/- 10% of non AST usually +/- 5%.

Page 9: Java JSON Benchmark

Who wrote benchmarks?

• Who wrote the benchmarks?

• They first version was written by Stephane Landelle of Gatling fame and performance expert

• Later they were added to by Andrey Bloschetsov for Groovy serialization

• Rick Hightower added new tests as well

Page 10: Java JSON Benchmark

Relationship to Groovy JSON parser for 2.3?• Andrey Bloschetsov and Rick Hightower, with the help of the

Groovy lead developers, took the Boon classes mostly written by Hightower and forked them into Groovy 2.3

• Mainly for parsing, but we also improved the JSON serialization speed

• Boon and Groovy parsing are unsurprisingly very comparable

• Groovy JSON parsing is a bit faster in a few use cases, and Boon parser is a bit faster in a few uses cases, but mostly they are neck in neck

• Boon JSON de-serialization (from JSON into instances of Classes) is still quite a bit faster than Groovy. This will change in Groovy 2.4 or 2.5

• The new Groovy JSON parser based on Boon is 20x faster than the Groovy 2.2 parser

Page 11: Java JSON Benchmark

Are the benchmarks flawed and do they allow JIT dead code

elimination?• Unlikely

• The benchmark uses JMH. JMH is what the OpenJDK uses for benchmarking. JMH endeavors to eliminate JIT dead code elimination.

• See full benchmarks here (https://github.com/RichardHightower/json-parsers-benchmark/blob/master/README.md)

11

Page 12: Java JSON Benchmark

JMH BlackHole

Page 13: Java JSON Benchmark

JMH BlackHole

Page 14: Java JSON Benchmark

Allows no DEAD CODE JIT ELIMINATION

Page 15: Java JSON Benchmark

Running JMH• For most tests parser are warmed up after

two JMH runs. For some tests Jackson needed a few more warmups and it was accommodated with extra warmup time

Page 16: Java JSON Benchmark

Boon JSON Caveats• Boon JSON parser is a parser optimized for REST and WebSocket style services.

• Boon JSON parser is optimized to work in a reactive style environment like Akka, Vert.x, etc. Boon JSON parser would work well with MessageDrivenBeans (EJB or Spring).

• For some use cases it runs stateless faster than Jackson runs with shared buffers.

• Jackson can handle very large JSON files and very large JSON streams. This support was added to Boon JSON as part of the fork/port to Groovy JSON. With larger files the speeds are much more equivalent, and in fact Jackson might be 10% faster or so.

• Benchmark first.

• It would take some extra effort to get superior results in a Servlet environment (it can be done).

• Jackson is mature and solid. Don't assume ripping out Jackson for Boon will buy you anything. Jackson has tooling that makes it work really well in a Java EE environment, and is more fool proof.

Page 17: Java JSON Benchmark

JSON from Files

Page 18: Java JSON Benchmark

JSON from InputStream

Page 19: Java JSON Benchmark
Page 20: Java JSON Benchmark
Page 21: Java JSON Benchmark
Page 22: Java JSON Benchmark

Object Serialization

• Java Boon and Jackson are faster than Java ObjectOutputStream and ObjectInputStream

• Java Boon is 85% of the speed of Kryo which is the fastest binary serializer

Page 23: Java JSON Benchmark
Page 24: Java JSON Benchmark

• Boon JSON support is also really good at doing weird JSON encoding.

Page 25: Java JSON Benchmark
Page 26: Java JSON Benchmark

• Why Boon?

• Easily read in files into lines or a giant string with one method call. Works with files, URLs, class-path, etc. Boon IO support will surprise you how easy it is. Boon has Slice notation for dealing with Strings, Lists, primitive arrays, Tree Maps, etc. If you are from Groovy land, Ruby land, Python land, or whatever land, and you have to use Java then Boon might give you some relief from API bloat. If you are like me, and you like to use Java, then Boon is for you too. Boon lets Java be Java, but adds the missing productive APIs from Python, Ruby, and Groovy. Boon may not be Ruby or Groovy, but its a real Boon to Java development.

Page 27: Java JSON Benchmark

Why Faster?

Page 28: Java JSON Benchmark

Why Faster? Continued