0

On my Drupal 7 site I have some heavy performance problems. I found out (with XHProf) that the cause of that problem are some Views. The strange thing is: not the query build time nor the query execute time are to slow, but the views rendering time:

Query build time    4.83 ms
Query execute time  3.29 ms
View render time    1175.82 ms 

The view is complicated because it has 7 relations. So that its build and execute time is as long as it actually shows up in the example above, is what one would expect. But the rendering can not depend on the complexity of the query, right? But only on the complexity of the resulting array or something else. So, my question is, where to start to optimize View render time?

ps.: If the view is cached it much faster. But I have to optimize its over all execution time, when it's not cache or can't be cached.

  • 1
    If you have xhprof, you should be able to find out what specifically takes so much time. If you're displaying rendered entities, then it's possible that a module does crazy things in a view-related hook. – Berdir Jul 16 '13 at 17:58
  • @Berdir The hint with the rendered entities, is extremely useful, thank you, I will flow that trace. – user5950 Jul 16 '13 at 18:41
  • How many results are you getting? In some instances, views will do node_load_multiple() instead of JOINing the fields. This can really hinder performance. – mpdonadio Jul 17 '13 at 3:05
  • @MPD Actually it is limited to only one row. – user5950 Jul 17 '13 at 4:35
  • I know this very old, but I'm having the same problem. Did you manage to fix it? – Chris Jul 6 '18 at 5:49
-1

Views can create real bottleneck for scaling and often cause great head ache by becoming resource hungry if not optimized well. Especially the use of Left Joins instead of Inner Joins, the default pagination in views and features like Distinct are major causes for the same.

The below code is a quick sample implementation which probably could fix the join issue in a view.

/**
* Implements hook_views_query_alter().
*
* This disables distinct and turns LEFT joins into INNER joins. This increases
* performance.
*/
function my_module_views_query_alter(&$view, &$query) {
if ($view->name == "my_view") {
$query->table_queue['content_type_article']['join']->type = 'INNER';
$query->distinct = 0;
}
}

Also, check if you can enable views cache. You can set the interval to something based on your update frequency or try to clear views_cache when something is updated on the site.

Use of views_litepager instead of the default page can also help, if you are using pagination in views.

There are several things you can do. You could read this detailed post on the topic for a more detailed understanding.

  • 3
    This would be a good tweak, but I don't think this will apply to the OP's problem. It's related to rendering time, which is all about rendering the query results, and you can see the query time is very small. Left and inner joins are not interchangeable. Besides, you don't need to alter the query in this way. If you mark the relationship as a required one, Views will use an INNER join. – AyeshK May 19 '14 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.