While working on making the breadcrumbs block cacheable, I noticed that they are also being rendered in template_preprocess_page().

So I put a strategic "early return" statement in template_preprocess_page(). In a place where the DB should not be touched at all:

  1. At /node from 224 DB queries to 211. 13 DB queries saved!
  2. At /taxonomy/term/1 from 207 DB queries to 185. 22 DB queries saved!

AFAICT in D7, breadcrumb building was tied to menu tree building so it didn't trigger additional DB hits. But in D8, it's a stand-alone concept. So there are DB queries for it, even when you don't use them!


Plus, there is a lot of cruft in there that should never ever be used, like

  $variables['base_path']         = base_path();

(Typically used for hardcoding links, which breaks when a site is multilingual, and for referring to images, which breaks when the site is integrated with a CDN.)

Comments

Wim Leers’s picture

Status: Active » Needs review
FileSize
498 bytes
Wim Leers’s picture

This should probably be taken on by somebody who knows the theme system sufficiently well to know which things can be removed.

Note that the following issues should help in removing the majority of what's in template_preprocess_page():

Cottser’s picture

Issue tags: +Twig
tim.plunkett’s picture

Status: Needs review » Postponed (maintainer needs more info)

Were you by chance tracking these with debug() calls and with dblog on? That would double the count...

On /taxonomy/term/{term}, I see
2 calls to SELECT tag, invalidations, deletions FROM {cache_tags} WHERE tag IN (:tags)
3 calls to SELECT cid, data, created, expire, serialized, tags, checksum_invalidations, checksum_deletions FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN (:cids)

And 1 query for the taxonomy breadcrumb.

All of those will be moved when they turn into blocks, but they'll still be called.
So I'm not 100% sure this is worth worrying about.

dawehner’s picture

ping @wim

alexpott’s picture

Status: Postponed (maintainer needs more info) » Postponed
catch’s picture

Title: template_preprocess_page() performs ~20 DB queries » Breadcrumbs are generated in template_preprocess_page() even if they aren't rendered
Priority: Critical » Major
Status: Postponed » Active

I think this is the right status? Or if it's critical and postponed on #2005546: Use branding block in place of page template branding variables (site name, slogan, site logo) then that issue needs to be bumped to critical.

Wim Leers’s picture

Issue tags: -sprint

Confirmed that this no longer causes 20 extra DB queries (instead, it causes zero extra queries!). The clean-up that we've done so far has severely diminished the problem indeed.

Wim Leers’s picture

Wim Leers’s picture

Status: Active » Closed (duplicate)

No trail of breadcrumbs (pun intended) in template_preprocess_page() anymore. Must've been removed elsewhere. Hurray!