Analysis of JSON parser for Elixir

Mar 18, 2019 . 2 mins read

Well, Elixir is been moved into production in serious environments. One of the major deployment, I came across is JSON API or JSON related endpoints on Elixir application.

We have observed that, Poison used to be and still being used as JSON parser in many major modules. Now, Jason is default in phoenix application, for its performance upgrades.

This is good for small scale application, but when the application has to process 5MB/sec and when application have to process about 4–5TB/data a day. Even Jason falls short.

Today, we look at various implementation of Json parser and results we experienced.

List consists of -

  1. Poison
  2. Jason
  3. Jiffy (eljiffy elixir wrapper)

Poison — Is probably the first JSON parser in Elixir ecosytem.

Jason — Build after seeing short comings of Poison, having the similar functions to help in migration and been using in phoenix framework since 1.4.

Jiffy — Not exactly a Elixir/Erlang module, it is C NIF to erlang ecosystem.

Code Migration is pretty straight forward.




Integration with phoenix with Jiffy.

config :phoenix, :json_library, Poison

config :phoenix, :json_library, Jason

config :phoenix, :json_library, Phoenix.Jiffy

Following are server outputs, we found.

CPU load when Jason is used

CPU load when Jiffy is used

We observed a drop of 40–50% load on CPU, when we are using jiffy endpoint.

For benchmark comparison, Jason developer has some benchmarks

Operating System: macOS
CPU Information: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.7.0-dev
Erlang 21.0
Benchmark suite executing with the following configuration:
warmup: 5 s
time: 30 s
memory time: 1 s
parallel: 1
inputs: Blockchain, Giphy, GitHub, GovTrack, Issue 90, JSON Generator, JSON Generator (Pretty), Pokedex, UTF-8 escaped, UTF-8 unescaped
Estimated total run time: 42 min
##### With input Blockchain #####
Name             ips        average  deviation         median         99th %
jiffy         3.18 K      314.79 μs    ±37.55%         282 μs         840 μs
Jason         2.30 K      434.06 μs    ±25.97%         401 μs         860 μs
jsone         1.57 K      636.05 μs    ±14.50%         634 μs         913 μs
Tiny          1.38 K      723.70 μs    ±12.66%         720 μs         975 μs
Poison        1.24 K      803.48 μs    ±12.08%         788 μs        1040 μs
JSX           0.99 K     1012.25 μs    ±13.43%        1004 μs     1428.19 μs
JSON          0.56 K     1775.23 μs    ±10.56%        1754 μs        2310 μs

Jiffy is clear winner in terms of performance and memory.

Most people stayed away from jiffy because of lesser popularity and no wrapper until now, there are many hidden gems in hex binaries.