Groovy 2.3 gets a much faster JSON Parser
Groovy 2.3 will ship with one of the fastest JSON parsers on the JVM, according to Rick Hightower, the ubiquitous consultant and author. In his article on JSON serialization benchmarks, Hightower claims that Groovy's JSON support and the Boon JSON parser are up to 3 to 5 times faster than the current Jackson parser at parsing JSON from String and char arrays, and 2 to 4 times faster at parsing byte arrays.
Russian developer Andrey Bloschetsov created a json-benchmarks GitHub project with the aim of benchmarking each of the popular JVM parsers against each other. The project compares performance between Jackson, Gson, Boon, and Groovy 2.3.
To test each parser, data was selected that has many different variations in structure:
- citys - A large array (29470 items) of simple objects. The compact json representation takes about 2.5 MB.
- repos.json - An array of four objects with complex structure. The compact json representation takes about 342.8 kB.
- user.json - one object with a complex structure. The compact json representation takes about 4.2 kB.
- response.json - one object with a simple structure. The compact json representation takes about 425 B.
Serialization was tested with two variants:
- pojo - Objects were presented as POJO objects.
- maplist - Objects were presented as Maps.
Deserialization was tested only with a single transformation use-case: from Strings to Maps.
The race concluded with Boon in first place, Groovy 2.3 placing a strong second, Jackson finishing third, and Gson following in last place.
To learn more about what this means for Groovy, InfoQ talked with Guillaume Laforge, Groovy Project Manager at Pivotal.
InfoQ: What made you decide to fork Boon and use it in Groovy 2.3?
I've been following Rick Hightower's work on his Boon framework, and was impressed by the speed he was getting out of his JSON parsing technique. So I contacted him to ask him if it was possible to retrofit this parsing technique to our existing JSON support that I had developed years ago for Groovy. Rick kindly offered to help, forking Boon to make it the underlying parsing technology of our JSON parsers. And the results published in his benchmarks are pretty impressive, to say the least.
InfoQ: How much faster is JSON parsing in Groovy 2.3 than in prior versions?
Obviously, it highly depends on the kind of JSON payload you're working with, how you measure, etc, but from what I gather from the benchmarks, you can assume that Groovy's JSON parsing (and hence Rick's Boon parsers) is at least 3 to 4 times faster than other JSON libraries available today.
When will Grails users be able to take advantage of Groovy 2.3?
Our plan is to release Groovy 2.3 within a week or so, so that Grails 2.4 can integrate Groovy 2.3 for its release targeted for mid-May. The second milestone of Grails 2.4 released this week actually already bundles Groovy 2.3-beta-2. So it's just a matter of weeks before Grails users can take advantage of Groovy 2.3.
So the link to my benchmark** is actually not my benchmark, it is me talking about Andrey's benchmark. The link to my benchmark with an FAQ, methodology, how we avoided JIT dead code optimizations to make the test meaningful, graphs, links to source code, quotes from experts who peer reviewed the benchmark, etc. is here:
link to my benchmark
You are welcome to use the a graph for this article. I like the blue and green one. It is pretty. 3 to 5x is for String and Reader.
(** "My Benchmark" was forked from Stephane Landelle benchmark, and I kept adding to it. Stephane Landelle is a performance testing guru of Gatling fame. Gatling is similar to JMeter or Grinder, but better. Stephane Landelle was the first user of Boon JSON outside of me. I wrote Boon JSON support but it would not exist as it is today without Stephane writing the benchmarks and taunting me. Also the Boon parser got a LOT better after merge forking it into Groovy. The key is to get a lot of help from smart people. I learned tons from Guillaume Laforge and crew. :)
** Side note: Back when I use to speak at conferences, people would often come up to me and say hi Matt. I had to start a lot of talks with "I am not Matt Raible".
Matt Raible, the ubiquitous consultant and author, is more like it. I have learned a ton about frameworks over the years by downloading appfuse and seeing what Matt figured out. :)
Todd Montgomery Dec 19, 2014