In my views, I am rendering a partial. This is actually a row element that shows up in a table some 500 – 600 times. I have eager loaded all associations.
But, the issue is, same partial takes abruptly different render-time some times.
My rails server o/p:
Rendered admin/invoices/_update.html.erb (1330.3ms)
Rendered admin/invoices/_update.html.erb (4.8ms)
Rendered admin/invoices/_update.html.erb (4.8ms)
Rendered admin/invoices/_update.html.erb (8.8ms)
Rendered admin/invoices/_update.html.erb (4.4ms)
Rendered admin/invoices/_update.html.erb (1309.9ms)
Rendered admin/invoices/_update.html.erb (4.7ms)
Rendered admin/invoices/_update.html.erb (4.6ms)
Rendered admin/invoices/_update.html.erb (4.6ms)
Rendered admin/invoices/_update.html.erb (1322.6ms)
Rendered admin/invoices/_update.html.erb (4.2ms)
Also, there is no particular row that takes longer every time.
In my view file:
<% @updates.each do |update| %>
<%= render :partial => 'update', :locals => {:user => update[0]} #each of this is a row %>
<% end %>
UPDATE:
Also suggest if this a good way to do this? i.e: looping over a partial so many times. I can’t use pagination and Ajax to fasten up things.! Any other approach.?
Though I’m not sure why the lag spikes in the rendering, i strongly recomend inverting the order: You give all the updates to the partial and inside it you iterate and render the rows.
In view file
And inside the update partial
This why you don’t suffer the partial loading overhead for every row in your update. Hope this helps!