Problem/Motivation

Found via #3537863: Optimize field module's hook_entity_bundle_info() implementation and roughly a similar problem.

When building bundle field definitions, we look for base field overrides for every bundle of every entity type. Some sites have several hundred bundles (custom blocks, paragraphs, webforms etc) and most sites have dozens.

However most sites only have a handful of base field overrides for one or two entity bundles.

This means we issue somewhere between dozens and several hundred entity queries during cache rebuilds, where 90-99% of them will return no results.

Instead, we can load all the base field overrides in one go, and static cache them on the class, then when we build the bundle field definitions, check that instead.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3538006

Command icon 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

catch created an issue. See original summary.

catch’s picture

Title: Optimize EntityFieldManager::buildBundleFielDefinitions() » Optimize EntityFieldManager::buildBundleFieldDefinitions()
catch’s picture

Status: Active » Needs work

It looks like there might be some variation in performance tests after this change, will probably need some debugging, but even with the variation there's an obvious measurable improvement.

catch’s picture

Status: Needs work » Needs review

Rebased and fixed a couple of tests.

berdir’s picture

Status: Needs review » Needs work

Needs a rebase on the performance tests.

catch’s picture

Status: Needs work » Needs review

Rebased.

catch’s picture

We should also be using memory cache in this class, but I didn't want to add it just for this property, but also didn't want to convert the 5+ static caches in here to it either, so hoping that can be a follow-up - would be a good one to do in general.

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#3554131: Add memory cache for EntityFieldManager

Let's do that as a follow up! Created here #3554131: Add memory cache for EntityFieldManager I might try to backport this to a site that having some performance issues likely due to the number of fields and paragraphs.

alexpott’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed d33c15d9f59 to 11.x and 43005e8159a to 11.3.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 43005e81 on 11.3.x
    Issue #3538006 by catch: Optimize EntityFieldManager::...

  • alexpott committed d33c15d9 on 11.x
    Issue #3538006 by catch: Optimize EntityFieldManager::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.