What is the fastest way to render json in rails

json, ruby-on-rails, ruby-on-rails-3

Solution

Rabl uses `multi_json` for compatibility across platforms and doesn't use the quite fast Yajl library by default. Rabl's config documentation explains the solution:

# Gemfile
gem 'yajl-ruby', :require => "yajl"

In the event that still isn't performant enough, you might want to explore a different JSON serializer like oj. You could also instrument your render and see where the bottleneck exists.

Problem

I'm optimizing some slow transactions in our Rails application and a I see significant time spent rendering JSON views: ``` Rendered welcome/index.json.rabl (490.5ms) Completed 200 OK in 1174ms (Views: 479.6ms | ActiveRecord: 27.8ms) ``` Assuming that the API call is returning exactly the data it needs to return, What is the fastest way to render JSON in rails? We are using Rabl because of the ability to share code easily, but we aren't tied to it.

Original source