3021: Use Oj to encode API responses, and to decode them in tests.
* We use the Oj and multi_json gems, which makes Oj the default JSON
parser. However, Rails' ActiveRecord::Base overrides this and uses
the native JSON parser, which is slow. In our case we have two
render() calls that represent nearly all cases where we ask
ActiveRecord to serialize for us. In both cases we already have a
hash (not a model object), and we always want JSON responses. So we
can fix the performance problem simply by calling Oj.dump()
ourselves, and passing the resulting JSON (instead of the hash) to
render().
More gory details:
* "ActiveRecord::Base.extend kills JSON performance":
https://github.com/rails/rails/issues/9212
* "when freedom patches fight, nobody wins":
https://github.com/intridea/multi_json/pull/138#issuecomment-
24468223