How to improve render html speed [closed]
My rails app works fine, but is too slow in rendering from DB. Example: "Completed in 4027ms (View: 3758, DB: 87)". Rails 2.3.8. How can I improve the html render speed in rails apps?
USING: action.html.er开发者_如何学运维b
I am sure:
- You are making queries inside your view
- You are rendering a lot of partial
- You are nesting rendering partials
- You are using expensive Ruby operations in your views (sorting, selecting, maping)
- You are nesting expensive operations (n2, n4... code)
Examples, to explain it:
- @my_objects = MyObject.where(:foo => :bar).all
- @my_objects.each{ |object| render object }
- @my_objects.each{ |object| render object }
_object.html.erb object.children.each{ |child| render child } - @my_objects.sort_by{ |a,b| a.id <=> b.id }
- @my_objects.sort_by{ |a,b| a.map(&:id).last.name <=> b.map(&:id).last.name }
1/ Probably you are making lots of things in your view (ordering or something). You could ask MySQL to do more job.
2/ You can use rails caching (actions, fragments ...)
精彩评论