[Ruby] String concatenation performance in Rails partials
Tom Lianza
tlianza at gmail.com
Sat Dec 9 15:44:04 PST 2006
On 11/29/06, Tom Lianza <tlianza at gmail.com> wrote:
>
> On 11/29/06, Eric Hodel <drbrain at segment7.net> wrote:
> >
> > On Nov 29, 2006, at 0113 , Tom Lianza wrote:
> >
> > So... it sems like that one, big string concatenation is what's sucking
> up all of the time. That makes me wonder if the issue doesn't have anything
> to do with lots of concatenations, but it has to do with the fact that there
> are two big strings being concatenated. I did some graphing, and the time
> seems to be linear with the amount of data in the output array.
>
> Any ideas on what might be going on? What seems to be taking all of the
> time is literally that one line ( <%=output%> ). It seems weird to me that
> this is slow, since I imagine it's common for ActionView to have to assemble
> multiple large chunks of HTML as it puts partials together.
FYI, I ended up finding out what the problem was here. I was using RJS to
render all of these partials, and RJS goes through and turns those partials
into JavaScript so it can do Element.Updates. It's extremely slow.
Fortunately they've patched it, and the fix will be available in Rails 1.2:
http://dev.rubyonrails.org/ticket/3473
The change in performance for my specific application was fairly dramatic.
After I trimmed out spaces, I was able to get 50 results down to
taking 1.8seconds without the patch. With the patch, the time dropped
to .2 seconds.
At 75 results I was up to about 3 seconds, and after the patch down to about
.3 seconds. So, for those of you who rely heavily on RJS templates, expect
a big improvement when Rails 1.2 comes out (or just grab that patch now).
Tom
More information about the Ruby
mailing list