Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Anonymous user, frontpage, without page_cache (entire request time 94ms).
In there we spend 1ms in theme_get_setting(), which does quite a lot:
Function Name | Calls | Calls% | Incl. Wall Time (microsec) |
IWall% | Incl. MemUse (bytes) |
IMemUse% | Incl. PeakMemUse (bytes) |
IPeakMemUse% |
---|---|---|---|---|---|---|---|---|
Current Function | ||||||||
theme_get_setting | 8 | 9.4% | 1,138 | 1.2% | 175,496 | 1.1% | 173,384 | 1.0% |
Exclusive Metrics for Current Function | 121 | 10.6% | 6,840 | 3.9% | 3,368 | 1.9% | ||
Parent functions | ||||||||
system_page_attachments | 3 | 37.5% | 1,036 | 91.0% | 174,120 | 99.2% | 173,384 | 100.0% |
template_preprocess_page | 3 | 37.5% | 61 | 5.4% | 736 | 0.4% | 0 | 0.0% |
_bartik_process_page | 2 | 25.0% | 41 | 3.6% | 640 | 0.4% | 0 | 0.0% |
Child functions | ||||||||
file_create_url | 2 | 2.9% | 568 | 49.9% | 118,088 | 67.3% | 110,760 | 63.9% |
Drupal::config | 2 | 2.9% | 195 | 17.1% | 10,608 | 6.0% | 38,376 | 22.1% |
Drupal\Core\Config\ConfigBase::get | 14 | 20.0% | 120 | 10.5% | 8,552 | 4.9% | 2,376 | 1.4% |
spl_autoload_call | 1 | 1.4% | 40 | 3.5% | 10,896 | 6.2% | 11,144 | 6.4% |
Drupal\Core\Config\ConfigBase::setData | 1 | 1.4% | 33 | 2.9% | 6,432 | 3.7% | 0 | 0.0% |
Drupal::theme | 8 | 11.4% | 18 | 1.6% | 632 | 0.4% | 584 | 0.3% |
Drupal\Core\Config\ConfigBase::set | 2 | 2.9% | 16 | 1.4% | 4,648 | 2.6% | 3,936 | 2.3% |
drupal_static | 8 | 11.4% | 9 | 0.8% | 944 | 0.5% | 944 | 0.5% |
file_exists | 1 | 1.4% | 6 | 0.5% | 624 | 0.4% | 0 | 0.0% |
Drupal\Core\Config\Config::get | 2 | 2.9% | 4 | 0.4% | 648 | 0.4% | 0 | 0.0% |
Drupal\Core\Extension\Extension::getPath | 2 | 2.9% | 4 | 0.4% | 864 | 0.5% | 0 | 0.0% |
Drupal::service | 1 | 1.4% | 3 | 0.3% | 632 | 0.4% | 0 | 0.0% |
_system_default_theme_features | 1 | 1.4% | 1 | 0.1% | 1,816 | 1.0% | 0 | 0.0% |
Drupal\Core\Theme\ActiveTheme::getName | 8 | 11.4% | 0 | 0.0% | 656 | 0.4% | 656 | 0.4% |
Drupal\Core\Extension\ThemeHandler::listInfo | 1 | 1.4% | 0 | 0.0% | 664 | 0.4% | 0 | 0.0% |
Drupal\Core\Theme\ThemeSettings::__construct | 1 | 1.4% | 0 | 0.0% | 664 | 0.4% | 576 | 0.3% |
in_array | 7 | 10.0% | 0 | 0.0% | 624 | 0.4% | 0 | 0.0% |
Drupal\Core\Theme\ThemeManager::getActiveTheme | 8 | 11.4% | 0 | 0.0% | 664 | 0.4% | 664 | 0.4% |
Proposed resolution
Try to cache the theme settings not in the request but between requests. One really good place could be the cache entry for the active theme object.
In case we would store it there, we would avoid the call to $themes = \Drupal::service('theme_handler')->listInfo();
in there.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#7 | 2531958-7.patch | 9.86 KB | claudiu.cristea |
Comments
Comment #1
dawehner@effulgentsia and myself talked about that and we agreed it would be worth try to cache this information.
In an ideal world file_create_url() would have the cacheablity metadata so the generated URL can be cached. For normal URls we rely on higher level render caching, but for this case, we could not.
Comment #2
claudiu.cristeaThe changes are few lines but the patch footprint is bigger because of indentation increase.
Comment #4
claudiu.cristeaWell, this is weird. Those tests are passing locally.
Comment #5
claudiu.cristeaComment #7
claudiu.cristeaOops. Sorry!
Comment #8
lauriiiComment #9
dawehnerThis is wrong. Use cache tags and be done.
Should we include the language at least in the caching? What do we do with config overrides? Things aren't simple sadly.
Comment #10
Wim LeersI'm afraid this is a dead end also :(
Tested with 1000 requests to
/contact
, as the anon users, with page cache off.Comment #11
dawehnerIt would be great to profile both issues at the same time.
Comment #12
claudiu.cristea@dawehner,
I'm using here
->listInfo()
and maybe this is slowing the whole stuff (?) I can drop the check of theme name and invalidate by tag. The cons is that we'll remove also other theme cache (and the global settings). Opinions?