views:

39

answers:

2

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 partial suggests) -- is Rails spending that 633ms concatenating strings? I feel like that (or any other CPU-bound operation) should be roughly infinitely fast.

A: 

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?

Open Source
+1  A: 

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.

Matchu
Do database queries run within the view count towards the "View" number or the "DB" number in `Completed in 841ms (View: 633, DB: 159)`
Horace Loeb
My thought would be that they should, but I wouldn't depend on it - also, DB doesn't include object instantiation.
Matchu