Increase performance by adding static cache in BehaviorConfigFactory and

Created on 23 May 2025, 10 days ago

Problem/Motivation

When an entity is being viewed. The entity type behaviors are also loaded. This uses the BehaviorConfigFactory to load all supported entity type behaviors for a given entity type / bundle.

However, the result of a scan is not cached. So when loading a page with a lot of entities, this leads to an unnecessary amount of of listing the config.

Example. We have 435 entities that are being loaded on an empty render cache.

This leads to almost 11k calls to getConfiguredBehaviors.

The getConfiguredBehaviors calls 11k times the getConfigDataForEntityTypeAndBundle. While the getConfigDataForEntityTypeAndBundle 11k times calls unserialize on the data.

getConfiguredEntityTypesAndBundles (called 435 times) also requests a listing of all the config every time and scans the list for behaviors.

$configNames = $this->configFactory->listAll($prefix);

The impact here isn't the same as the getConfiguredBehaviors, as core has static cache for the listing. But we shouldn't request it, if we already have calculated the configured ones before.

Steps to reproduce

Clear the cache and go to a random page with multiple entities on. After that also go to a second page.

Proposed resolution

At least introduce static cache. But we probably can also extend it to cache the result permanently. Configured behaviors only change when changing config. So there is no need to calculate this every time.

Remaining tasks

Implement cache

📌 Task
Status

Active

Version

2.1

Component

Code

Created by

🇧🇪Belgium nils.destoop

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024