Justin Chen
2006-Jul-13 19:35 UTC
[Rails] Performance diff between rendering partial vs. calling a helper?
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/7163e21c/attachment.html
Eric Anderson
2006-Jul-13 20:17 UTC
[Rails] Re: Performance diff between rendering partial vs. calling a helper?
Justin Chen wrote:> Is there any performance difference between rendering partials vs. > calling a helper? When we initally started coding we built a bunch ofPartials 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
Justin Chen
2006-Jul-13 23:58 UTC
[Rails] Re: Performance diff between rendering partial vs. calling a helper?
Thanks for the explanation and advice! Justin On 7/13/06, Eric Anderson <eric@afaik.us> wrote:> > Justin Chen 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/b80c3e5a/attachment.html
Stefan Kaes
2006-Jul-14 11:40 UTC
[Rails] Re: Performance diff between rendering partial vs. calling a helper?
Eric Anderson wrote:> Justin Chen 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