开发者

How to improve render html speed [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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:

  1. You are making queries inside your view
  2. You are rendering a lot of partial
  3. You are nesting rendering partials
  4. You are using expensive Ruby operations in your views (sorting, selecting, maping)
  5. You are nesting expensive operations (n2, n4... code)

Examples, to explain it:

  1. @my_objects = MyObject.where(:foo => :bar).all
  2. @my_objects.each{ |object| render object }
  3. @my_objects.each{ |object| render object }
    _object.html.erb object.children.each{ |child| render child }
  4. @my_objects.sort_by{ |a,b| a.id <=> b.id }
  5. @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 ...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜