Oj: OPTIMIZED JSON
Ryan Perrin
Brandon Weaver
It is:
A JSON parser/serializer/deserializer.
A C extension to Ruby.
Pitched as being significantly faster than other parsers.
Why Oj over JSON?
Doesn't have many of the inefficiencies that JSON has:
Doesn't parse JSON into Ruby Objects.
Doesn't rely on the Ruby GC for cleanup.
Also: Did I mention it is fast?!
Benchmarks
We've spent time speaking to how good Oj is.
How good is good?
Other Alternatives
JSON
JSON_Pure
YAJL
Scope of Upgrade
Involves changing all JSON.parse to Oj.load.
Use oj_mimic_json gem (Rails 4.1).
Some test fixes.
Abstraction with Multi_Json
Multi_json provides an abstraction layer for JSON parsers.
Allows the developer to switch out adapters easily and without many code changes.
Uses JSON, gem in Gemfile or manually configured adapter.
Unfortunately: Reduction in performance.
Useful Links
oj: https://github.com/ohler55/oj
multi_json: https://github.com/intridea/multi_json
Benchpress: https://github.com/baweaver/Benchpress
What does it all mean!?
On average, Oj is:
~10% faster than JSON for smaller files.
~7.5% faster for larger files.
Or, for those who don't like math:
Between 25-700ms faster.
This may not seem like much, but...