Rails Partial (Rails 3, HAML) arbitrarily slow

旧时模样 提交于 2019-12-12 21:18:53

问题


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)

回答1:


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.




回答2:


Maybe its faster if you put it into one single partial?

I mean to put it into a

# tasks/_incomplete_tasks.haml instead of tasks/_incomplete_task.haml

partial, which is called 1 time.. and not 1000 times...




回答3:


Put in .bashrc:

export RUBY_GC_HEAP_INIT_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=500000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000

Source, and restart server

$> source ~/.bashrc
$> rails s

Depending on what is your problem, this might make rendering your partials faster (in my case, average rendering time got x3 faster).



来源:https://stackoverflow.com/questions/4007065/rails-partial-rails-3-haml-arbitrarily-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!