Get the latest tech news

Optimizing Ruby's JSON, Part 1


I was recently made maintainer of the json gem, and aside from fixing some old bugs, I focused quite a bit on its performance, so that it is now the fastest JSON parser and generator for Ruby on most benchmarks.

Writing a native gem isn’t inherently hard, but it does require some substantial understanding of how the Ruby VM works, especially its GC, to not cause crashes or worse, memory corruption. So my motivation was to hopefully make ruby/json perform about as well as oj on both real-world and micro-benchmark so that users would no longer feel the need to monkey patch json for speed reasons. The idea of lookup tables is that you precompute a static array with that algorithm so that instead of doing multiple comparisons per character, all you do is read a boolean at a dynamic offset.

Get the Android app

Or read this on Hacker News