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!