hook_entity_extra_field_info() is called unnecessarily often, hurting performance

Created on 6 September 2021, almost 3 years ago
Updated 1 August 2023, 11 months ago

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.

Original issue summary

getExtraFields uses static to avoid extra calls.
But if some entity has no extra fields, it will call $this->moduleHandler->invokeAll('entity_extra_field_info') again for all entities.
In my example, it was called in total 213 times and took 15 sec, instead of call just once as it gets data for all entities at once.

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
EntityΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡·πŸ‡ΊRussia kiseleva.t

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024