ruby-on-railsrubyruby-on-rails-3hamlmongrel

Rails Partial (Rails 3, HAML) arbitrarily slow


I'm using Rails 3.0.1, HAML 0.3.22, and Mongrel 1.1.5 (and MongoMapper not AR). I'm rendering a list, and each list item is it's own partial. Every time the page renders one of the list item partials takes almost 100X longer to render (and it is an arbitrarily different one each time. Also, needless to say, each item has essentially the same data).

Any idea what is going on here? Should I move the logic into a block rather than a partial?

Rendered shared/_head.html.haml (5.6ms)
Rendered tasks/_incomplete_task.haml (6.2ms)
Rendered tasks/_incomplete_task.haml (6.4ms)
Rendered tasks/_incomplete_task.haml (6.9ms)
Rendered tasks/_incomplete_task.haml (6.2ms)
Rendered tasks/_incomplete_task.haml (6.0ms)
Rendered tasks/_incomplete_task.haml (6.1ms)
Rendered tasks/_incomplete_task.haml (6.4ms)
Rendered tasks/_incomplete_task.haml (6.2ms)
Rendered tasks/_incomplete_task.haml (7.0ms)
Rendered tasks/_incomplete_task.haml (531.6ms)
Rendered tasks/_incomplete_task.haml (8.0ms)
Rendered tasks/_incomplete_task.haml (6.8ms)
Rendered tasks/_incomplete_task.haml (6.5ms)
Rendered shared/_tasks.html.haml (633.0ms)

Solution

  • 6 msec per partial seems too high but it really depends on what are you doing inside the partial (any SQL queries there?)

    As for 500 msec thing I've noticed same behavior in my app. And I've invested some time to dig inside. And well (in my case) it really was Ruby garbage collector.

    You can use REE when you can fine tune the garbage collector (for example here http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/).

    You can play with those numbers and see if the behavior of your application will change. And if so then blame the GC.