`hook_entity_extra_field_info()` is called unnecessarily often, hurting performance

Created on 28 August 2023, about 1 year ago
Updated 29 August 2023, about 1 year ago

Problem/Motivation

This is a port of the work done in 🐛 hook_entity_extra_field_info() is called unnecessarily often, hurting performance Fixed .
This fortunately lands in Drupal Core 10.1.x and 11.x however as we're still in the midst of updating towards Drupal 10.0.x we have decided to backport this issue for Open Social and Drupal 9.5.x for the time being.

For any of the other details for this issue I recommend you to take a look at the issue over at 🐛 hook_entity_extra_field_info() is called unnecessarily often, hurting performance Fixed .

Copied from that issue summary:

Problem/Motivation
EntityFieldManager::getExtraFields() invokes hook_entity_extra_field_info() every time it is called with a different combination of entity type, bundle and language. In some real world use cases, it can amount to a large number of function calls and have a noticeable negative impact on performance.

The problem is that hook_entity_extra_field_info() collects and return extra field info about all entity types and bundles. Therefore it could be called only once per language, instead of being called once per entity type, bundle and language.

Proposed resolution
Cache the result of hook_entity_extra_field_info() the first time EntityFieldManager::getExtraFields() is called, then reuse the cached data for subsequent calls.

There is a balance to find between performance, permanent cache size increase and static cache size increase.

For some impact analysis check:
https://www.drupal.org/project/drupal/issues/3231503#comment-15130610 🐛 hook_entity_extra_field_info() is called unnecessarily often, hurting performance Fixed

📌 Task
Status

Fixed

Version

11.10

Component

Code (back-end)

Created by

🇳🇱Netherlands ronaldtebrake

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

Comments & Activities

Production build 0.71.5 2024