Our application does a fair amount of work with reasonable size JSON documents that range in size from 500KB to 200MB in size. So performance of the JSON serializer matters here, more so than in most web applications sending around small bits of json around an API exposed over HTTP. So I sat down and measured some (most?) of the JSON libraries available.
The test consisted of taking a smallish file 1.5MB in size with a bit fewer than 2600 JSON objects in it, each of which have a dozen or so fields, including some further objects. The data in this file was then parsed a number of times (6 by default) in serial and then again in parallel by Poison, Jiffy, JSON, JSX, and ExJSX.
Here is an Elixir module containing the benchmark, and to use it you will need the following in your mix.exs file:
{:jiffy, "~> 0.14.11"},
{:json, "~> 1.0"},
{:jsx, "~> 2.8"},
{:exjsx, "~> 4.0"},
{:benchee, "~> 0.9.0"},
{:benchee_html, "~> 0.3"},
{:poison, "~> 3.1"}
You can see typical results here. I have run this benchmark several times now and the results are rather consistent. It is impressive how much faster Jiffy is, which can be explained by it being implemented as a NIF, but also how well Poison does given it is written in pure Elixir.
Note that the parallel and sequential versions are not really directly comparable as there is extra overhead there in the form of a fairly naive message passing mechanism to wait on the returns, but as that overhead is the same across all parallel runs they are comparable. It is interesting to see how the different libraries experience different amounts of speed ups, ranging from ~3.5x to ~4.5x, with Jiffy getting the least amount of benefit, again probably due to being a NIF.
Thought it might be of interest to others ā¦ Iāll be looking at memory consumption next as well as running with larger files as well ā¦
Cheers!