Rails Partial(Rails 3,HAML)任意慢 [英] Rails Partial (Rails 3, HAML) arbitrarily slow

查看:121
本文介绍了Rails Partial(Rails 3,HAML)任意慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.0.1,HAML 0.3.22和Mongrel 1.1.5(而MongoMapper不是AR).我正在渲染一个列表,每个列表项都是它自己的部分.每次页面渲染列表项部分之一时,渲染时间几乎都要长100倍(并且每次渲染的时间都是任意不同的.而且,不用说,每个项目都具有基本相同的数据)..............................................................................................................................

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)

推荐答案

每个部分6毫秒似乎太高了,但这实际上取决于您在部分(内部是否有任何SQL查询?)内部做什么?

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

关于500毫秒的事情,我在我的应用中注意到了相同的行为.而且我花了一些时间在里面进行挖掘.好吧(以我为例),它确实是Ruby垃圾收集器.

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.

当您可以微调垃圾收集器时,可以使用REE(例如,此处 http://www.coffeepowered.net/2009/06/13/fine-tuning-your-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/).

您可以使用这些数字来查看应用程序的行为是否会改变.如果是这样,那就怪罪GC了.

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

这篇关于Rails Partial(Rails 3,HAML)任意慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆