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)
Comment | File | Size | Author |
---|---|---|---|
#3 | 2067759-3.patch | 1.85 KB | thedavidmeister |
#1 | 2067759-1.patch | 1.85 KB | thedavidmeister |
Comments
Comment #1
thedavidmeister CreditAttribution: thedavidmeister commentedPatch attached.
Comment #3
thedavidmeister CreditAttribution: thedavidmeister commentedyeah, that fail makes sense.
Comment #5
pounardI'd be curious to see benchmarks of this.
Comment #6
sunThis 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.