dan
dan

Reputation: 1080

Is there a significant performance cost to using lots of nested partials?

I have a page that uses a lot of nested partials to display content according to user type and product status across a range of categories. Is it a good idea to manage this using nested partials and conditional status? I wonder if there is a performance hit to all of this?

For example - product.html.erb:

<% if product.status == "available" %>
  <%= render available_product %>
<% else %>
  <%= render manage_supplier %>
<% end %>

And available_product.html.erb:

<% if @user.role == owner %>
  <%= render product_headline_form %>
<% else %>
  <%= render product_headline_show %>
<% end %>
<%= render some_nice_stuff_from_supplier %>

... and on.

I'm keeping my partials pretty atomised 'cos I figure it will give me more flexibility when I come to add ajax in places.

Upvotes: 0

Views: 366

Answers (1)

phoet
phoet

Reputation: 18845

that depends on

  • the ruby version
  • the rails version
  • your partials

in other words: you have to measure

in general: partials tend to be much slower than ie helpers because rails has to do much more work to setup the rendering context for a partial than it has to do if there are none.

is it relevant? depends on your requirements.

Upvotes: 1

Related Questions