### 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, significantly impacting performance.
### Performance Impact
Testing on a Drupal 10.5.6 node edit page:
| 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 |
### Root Cause
In `site_settings.module`, the preprocess hook creates a new loader instance for each template, and since
`$this->settings` is an instance property (not static), each new instance makes a fresh cache lookup.
### Proposed Resolution
Add a static cache property that persists across plugin instances within a single request:
1. Add `protected static $staticSettingsCache = [];`
2. Check static cache before backend cache in `loadAll()`
3. Update `clearCache()` and `rebuildCache()` to maintain consistency
### Why More Visible in Drupal 10.5.6+
Drupal core changes (Issues #3548313, #3555720) between 10.5.4 and 10.5.6 changed entity revision queries,
resulting in ~3.4x more template renders on the same page, making this pre-existing inefficiency much more
noticeable.
### Related Issues
Similar fix for Metatag module: https://www.drupal.org/project/metatag/issues/357736
| Comment | File | Size | Author |
|---|
Issue fork site_settings-3578375
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
moneeshk commentedComment #4
moneeshk commentedComment #5
moneeshk commentedPatch for 2.0.5
Comment #6
scott_euser commentedSetting back to normal per https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-... - valid workaround is use the full site settings loader (recommended). Also changing to task since its already got a cache layer which is not broken and could be a negligible win if the cache backend you use is already e.g. a memory one
In any case this looks fine though thanks!
Comment #8
scott_euser commentedComment #10
scott_euser commented