I've been working with Drupal for a little while now and one nagging question I've had is about whether or not logic in my *.theme or *.module files have any impact on server load.

Let's say I have this bit of code in my *.theme file:

 * Implements hook_theme_suggestions_HOOK_alter().
function MY_THEME_theme_suggestions_page_alter(array &$suggestions, array $variables) {

  if(\Drupal::routeMatch()->getRouteName() == 'entity.node.edit_form' && \Drupal::routeMatch()->getParameter('node')->bundle() === 'blog_general') {
    $suggestions[] = 'page__no_sidebars';

This bit of code adds a template theme at the page.html level. I only need this for about 1% of my site and it bothers me a little that this would need to execute on every page load just so 1% of my site can templated correctly.

So my question is, would this code get executed on every page load? Or does the caching take care of it? If it does execute on every page load then this one bit of code might be trivial. However, I'm slowly building up a lot of these types of altering hooks and it's bugging me that they could be taxing the server.

I appreciate any insights. Thanks!

  • 1
    I think it caches as you need to clear caches when changing suggestions logic so you might want to check that. If it does it shouldn't be causing undue server load.
    – dibs
    Jun 17, 2019 at 23:36

1 Answer 1


To answer your questions:

  1. Yes, it executes on every page load.
  2. It won't impact your server load any noticeable amount.

The amount of processing power for that one function is extremely low. You could probably run it 1000 times without causing a noticeable performance it.

  • Thanks for the reply. I'll not worry about it going forward. Jun 18, 2019 at 23:09

Your Answer

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

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