Rails Partial (Rails 3, HAML) 任意慢

发布于 2024-09-29 12:54:17 字数 897 浏览 3 评论 0原文

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

知道这是怎么回事吗?我应该将逻辑移至一个块而不是部分吗?

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

來不及說愛妳 2024-10-06 12:54:17

每个部分 6 毫秒似乎太高,但它实际上取决于您在部分中做什么(那里有任何 SQL 查询吗?)

至于 500 毫秒,我注意到我的应用程序中有相同的行为。我投入了一些时间来深入挖掘。好吧(就我而言)它确实是 Ruby 垃圾收集器。

当您可以微调垃圾收集器时,您可以使用 REE(例如此处 http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/)。

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

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.

夜无邪 2024-10-06 12:54:17

如果将其放入一个单独的部分中,也许会更快?

我的意思是把它放入

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

部分,称为 1 次..而不是 1000 次...

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...

梦中的蝴蝶 2024-10-06 12:54:17

放入 .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

源代码,然后重新启动服务器

gt; source ~/.bashrc
gt; rails s

根据您的问题,这可能会使您的部分渲染速度更快(在我的情况下,平均渲染时间加快了 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

gt; source ~/.bashrc
gt; rails s

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文