0

I am currently trying to render a fairly large JSON, from a database model, with some translations using Globalize.

It seems the problem is at the rendering process, not at loading the model and his translations.

Completed 200 OK in 1141ms (Views: 990.6ms | ActiveRecord: 16.7ms)

The final JSON size is about 18k lines and it takes around ~2-3 seconds to complete the generation.

I tried to switch to oj, but I did not see any significant performance, is this normal ?

Also, I tried the surus gem, which works great (around 90ms), but it does not seems to support Globalize (which is normal, because it is working at the database level directly, no through ActiveRecord).

I was wondering if there is any other things I could use/check/try to improve the generation time ? Yes I could use some kind of caching, but I would like to avoid it, unless it is truly necessary.

Edit: We are still using Rails 3.x, I don't know if there is any improvement on this topic in Rails 4.x.

Pierre-Olivier
  • 3,104
  • 19
  • 37
  • 2
    Are you sure the JSON generation is the problem? Last time I looked at Globalize it was doing insane things like hitting the database over and over again rather than using JOINs. – mu is too short May 30 '14 at 20:42
  • 2
    18KLOC for json is really large, but as @muistooshort mentioned, finding out exactly what's causing the huge delay might be a useful thing to do here. I would try [something really simple](http://www.skorks.com/2010/03/timing-ruby-code-it-is-easy-with-benchmark/) to find out which part of the code is taking a long time. – Jason Kim May 30 '14 at 21:24

0 Answers0