← Back to Upcase

Is there a cost to using partials?


(David Lee) #1

Following up on this interesting post (http://programmers.stackexchange.com/questions/157108/rails-does-using-partials-slow-views-rendering), what do you guys think of the cost of rendering a partial? For example, I have a search page that is showing 50 results. I had each result as a partial and additional partials in that “parent” partial (meaning many, many render calls on the single page). Any thoughts on whether partials should be used with restraint due to any time cost? For small traffic websites, this isn’t a big deal, but what about for high traffic sites?

Thanks!


(Jacob Evan Shreve) #2

Especially when used with caching, I don’t think they’re a big enough performance hit to be worried about. Partial rendering takes a couple milliseconds according to my New Relic reports.

DHH talks about how basecamp got so fast, and part of it involves using, and caching partials.


(Sean Griffin) #3

There’s a cost, and it’s non-trivial. However, if the difference between using a partial and not is significant enough to affect your application, you probably shouldn’t be using Ruby or Rails in the first place. Chances are, using partials isn’t going to be your bottleneck.