theme() is called a lot on every page. I'm not sure exactly how much, but I think it goes without saying that it's a popular function.

Calling functions is a slow thing to do, even if the function you're calling has implemented it's own static cache internally, the function call overhead can add up if you're doing it a few hundred times on a page load.

In drupal_static()'s own words:

In a few cases, a function needs a resettable static variable, but the function is called many times (100+) during a single page request, so every microsecond of execution time that can be removed from the function counts

I can see two things in theme() that look like they're potentially statically cacheable:

- Drupal::moduleHandler()->isLoaded()
- theme_get_registry(FALSE)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thedavidmeister’s picture

Status: Active » Needs review
FileSize
1.85 KB

Patch attached.

Status: Needs review » Needs work

The last submitted patch, 2067759-1.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
FileSize
1.85 KB

yeah, that fail makes sense.

Status: Needs review » Needs work

The last submitted patch, 2067759-3.patch, failed testing.

pounard’s picture

I'd be curious to see benchmarks of this.

sun’s picture

Issue summary: View changes
Status: Needs work » Closed (duplicate)

This issue appears to be obsolete; #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()

#2228093: Modernize theme initialization or a separate issue related to it will convert the remainder of theme.inc + _theme() into proper services, which in turn means that all of these checks and local static caches will go away entirely.