AJAX slow - to_json responsible?

Hello.

I am building full-ajax back-end, which consits of many quite big
partials. As the system grows up, performance is problem. After every
click, partial is refreshed, if needed. I am now at 0.5 sec / request. I
tried to simply disable ajax and the result was quite suprising: the
same page is rendered over 2x faster. I update 80% of page in case of
ajax. (Please dont tell: dont use ajax when updating 80% of page…
thats not the point.) So the ajax (page.replace :partial=>) is
significantly slower than non-ajax? Are there ways to improve
performance? I’am not very deep in rails, some suggestions?

Thanks. Fero.

On 13 Mar 2008, at 16:51, Frantisek P. wrote:

thats not the point.) So the ajax (page.replace :partial=>) is
significantly slower than non-ajax? Are there ways to improve
performance? I’am not very deep in rails, some suggestions?

Well the first step is to workout where the bottleneck is (via ruby-
prof for example, there’s a rails plugin that’s easy to use).
Beyond that, it is certainly true that page.replace :partial=> is
slower than just a plain old render, since on top of the normal
render, the result of the render must be turned into a javascript
string (escaping quotes in it for example), and then on the other end
the browser does the exact opposite. I remember finding it a big
sluggish with large chunks of html.

Fred

I actualy found that cca half of request is in String#gsub, in 90%
called by String#to_json. Any idea how I should improve performance?

Frantisek P. wrote:

I actualy found that cca half of request is in String#gsub, in 90%
called by String#to_json. Any idea how I should improve performance?

maybe by using http://json.rubyforge.org/ c-variant of String#to_json

But, how can I do that?

Ok, my first performance-tunning success:

Using http://json.rubyforge.org/ the time calling String#to_json drops
to 4%, which improves overall rendering performance by 30%.

Thank you for attention :slight_smile: F.