I found that a page in my Drupal site is causing high CPU/memory loading, I tried to remove each item(e.g. block, custom PHP code and so on) on this page. Finally, I found that if I remove the code below will drop down the CPU/memory usage from 90% to 10%.

print views_embed_view('flag_compare', 'block_1');

Could someone suggest another function to embed view?

  • what are you trying to do in that "flag_compare" view?
    – uwe
    Feb 9, 2012 at 17:30
  • I placed this code in .tpl file and print out on a specific page. Feb 10, 2012 at 2:17

2 Answers 2


The function itself has not much to do with this, it is a wrapper for creating and displaying a view. The view you are displaying is a block - if you should have chosen to enable the block instead my guess is that the result would have been the same.

The most probable cause is the view you are displaying. Tools like views and panels are great at handling displaying stuff, but it comes at a price. They are usually a lot more ineffective than if you had done it with your own code, but they are also a lot faster to use. I would recommend that you review the view and try to find a way to reduce the workload by simplifying it, or if it's really important to you, do it yourself and skip a lot of the abstractions that Views bring.


You should not use views_embed_view in a tpl. Drupal will boostrap twice. Use a preprocess function are create a block and embed it in a region.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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