5 comments

[ 3.3 ms ] story [ 18.1 ms ] thread
How is "and there's nothing you can do" true? The article clearly describes how the author solved the problem in the context of their app, which is a generally applicable solution (that is, applying the same kind of fix that active support did that caused the problem, but using a higher-performance JSON solution than the one active_support hacked in to fix the original bug whose fix caused the poor performance.)
true that (but it is the title of the blog post)
I'm torn. On one hand, yes, this is unsatisfactorily slow.

On the other, all my experience has taught me that making objects (especially in the case of ActiveRecord objects that are mapped to database tables) directly responsible for their API serialisation leads to pain: those objects end up bloated, the API reflects internal concerns rather than usage patterns, and it's really hard to evolve the API or to provide multiple versions simultaneously.

So even though .to_json sucks, I'm far from convinced that it matters. I'd fix it by taking it out entirely!

Sure, we do, in fact, use RABL (https://github.com/nesquena/rabl) for much of our JSONifying needs. In general a much better solution than calling .to_json on objects directly.

However, we also have situations where we have a reasonably large Hash that has a very trivial structure. In that case we do call .to_json directly on the Hash. And those are the situations where we're seeing a big performance hit.