Performance diff between rendering partial vs. calling a hel

Hi,

Is there any performance difference between rendering partials vs.
calling a
helper? When we initally started coding we built a bunch of small
partials
and if there is a significant performance overhead with them, we’ll
probably
try to switch them over to helpers. They seem like they would be quite
similar but I don’t know the full details of how partials are handled.

Thanks!
Justin

Justin C. wrote:

Is there any performance difference between rendering partials vs.
calling a helper? When we initally started coding we built a bunch of

Partials are just using the builtin ERB module that comes with Ruby. It
has to read in the template file, parse the ERB and generate ruby, then
eval the entire thing vs. just executing a function…

So if you really want to get to the nitty gritty partials should be
slower. You would have to do performance tests to find out how much.

That being said, this sounds like premature optimization to me. If your
performance tests tell you that you need to make your view render faster
then maybe consider doing this. But there are probably other ways to
increase performance that will deliver better results and keep your code
maintainable. When deciding between partials and helpers just figure out
what is the most maintainable. Only if you can measure a performance
problem should you make a decision to do something in a less
maintainable way. Otherwise you are just guessing and making your code
less maintainable.

Eric

Thanks for the explanation and advice!

Justin

Eric A. wrote:

Justin C. wrote:

Is there any performance difference between rendering partials vs.
calling a helper? When we initally started coding we built a bunch of

Partials are just using the builtin ERB module that comes with Ruby.
It has to read in the template file, parse the ERB and generate ruby,
then eval the entire thing vs. just executing a function…

This used to be the case in older Rails versions. Now, templates are
read only once and compiled into a render method, which will be called
when rendering the template. So this is a lot faster than it used to be.

However, there’s still some overhead over simply calling a helper
method: rendering a partial involves a few more method calls and some
hash massage before the partial render method is invoked.

– stefan


Rails performance tuning: http://railsexpress.de/blog
Subscription: http://railsexpress.de/blog/xml/rss20/feed.xml

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs