[LRUG] Fwd: Recommendations for Ruby & Rails optimisation resources
Garry Shutler
garry at robustsoftware.co.uk
Mon Nov 26 07:54:54 PST 2012
HAML can be extremely slow compared to ERB, particularly when you have
elements with multiple attributes (due to how it's careful to encode things
properly).
At Zopa we had an extreme case of a select list where we were generating
hundreds of options with a few data attributes. For that section we used
the literal syntax and only escaped the values/attributes that could be
potentially dangerous. Something like this: https://gist.github.com/4148888
After making that change the rendering went down to sub-second from 4-5
seconds if memory serves. It might be worth trying out if your markup is
within a loop and has a reasonable number of attributes. We didn't go as
far as converting the whole page to ERB as using that trick in that one
place was sufficient to get acceptable rendering speed.
*Garry Shutler*
@gshutler <http://twitter.com/gshutler>
evenitron.com
www.robustsoftware.co.uk
On 26 November 2012 15:36, Jonathon Horsman <jonathon at arctickiwi.com> wrote:
> Are you rendering a lot of partials? There's quite a bit of overhead
>> in setting up each partial, it can sometimes be worth flattening them
>> out.
>>
>
> This is an interesting one, I thought this too but timing before and after
> flattening shows that rendering partials is actually faster.
>
> So I have
>
> *= render :partial => "share", :collection => @shares*
>
> renders about 500ms faster than this:
>
> *- @shares.each do |share|*
> * <!-- inline row HAML ->*
>
>
> Also Paperclip was generating an image URL for each row:
>
> *= image_tag(country.flag.url(:normal), :alt => country.name, :title =>
> country.name)*
>
> By caching this in a hash (since there's only 8 different flags) seems to
> provide a significant speed up.
>
> Thanks for all the suggestions, I'm continuing with the profiling and have
> already had a ~1sec speed improvement.
>
> --
> Jonathon Horsman
> Director
> Arctic Kiwi
> Mobile: 079 42366038
> Web: http://www.arctickiwi.com
> Twitter: @jhorsman <http://www.twitter.com/jhorsman>
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20121126/185e3944/attachment.html>
More information about the Chat
mailing list