Issue #3578375: Performance: Add static caching to FlattenedSiteSettingsLoader::loadAll()

Problem/Motivation

The FlattenedSiteSettingsLoader::loadAll() method is called via site_settings_preprocess() for every Twig template rendered on a page. Since the loader plugin is instantiated fresh each time via getActiveLoaderPlugin(), the instance property $this->settings is always NULL, causing a cache backend lookup on every single call.

On a typical node edit page with ~4,000 templates, this results in ~4,000 unnecessary cache lookups per request.

Performance Impact

Metric Without Fix With Fix
loadAll() cache lookups 4,085 1
MemcachedDriver::getMulti calls 4,933 ~850
Wall time for site_settings 250ms <1ms
Total page load 3.1s ~2.6s

Solution

Add a static cache ($staticSettingsCache) that persists across plugin instances within a single request:

  1. Check static cache before backend cache lookup
  2. Store results in static cache after loading
  3. Clear/update static cache in clearCache() and rebuildCache()

Changes

  • Added protected static $staticSettingsCache = [] property
  • Modified loadAll() to check static cache first
  • Modified rebuildCache() to update static cache
  • Modified clearCache() to clear static cache

Merge request reports

Loading