开发者

What does Rails mean when it reports spending time rendering a view?

Here's an excerpt from my Rails log:

Rendered songs/_song_list (683.4ms)
Completed in 841ms (View: 633, DB: 159) | 200 OK

What does Rails mean when it reports spending 633ms rendering the view?

In this particular case I'm iterating through a collection of items and printing an <li> for each (as the name of the parti开发者_如何学运维al suggests) -- is Rails spending that 633ms concatenating strings? I feel like that (or any other CPU-bound operation) should be roughly infinitely fast.


Make sure that you aren't fetching from the database on every item. Preload everything you will need with the include option on find, or else, while the View is running, you will be running tons of queries and initializing new ActiveRecord objects, which is a huge time-waster.


View in this case means everything: The bootstrap, includes, initializations, everything. It still seems like a lot, though. What does time look like in a view that does nothing?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜