Speed Up JSON Operations With Oj Gem In Rails
Boost Rails JSON performance by 30-40% with Oj gem! Include in Gemfile, call Oj.optimize_rails in initializer and see significant execution time reduction.
You're probably generating JSON strings, or parsing them in your Rails app. Using gem "oj" can speed these operations up significantly.
Setting up is easy!
Just include the gem in gemfile, and call Oj.optimize_rails in an initializer.
On my M2 Mac I see a nice 30-40% execution time reduction.
Benchmark.bmbm do |x|
  x.report("jsonification") { 500_000.times { {"yay#{_1}" => true}.to_json } }
end
# without OJ
jsonification   0.929295   0.001351   0.930646 (  0.934957)
jsonification   0.937358   0.001534   0.938892 (  0.944757)
jsonification   0.999621   0.002159   1.001780 (  1.010062)
# with...