Problem/Motivation

TypedDataManager creates property prototypes - e.g. a typed data instance of 'field_something' based on the entity/bundle/field name and static caches them. This is so that if multiple entities of the same type are loaded and the same fields are requested, it doesn't have to create the full typed data object every time.

However, this static cache also stores the parent typed data object within the prototype. When the parent is an entity object, this creates a static cache of entities that can never be cleared, making entity LRU caching ineffective. It will only include the entities for the first time a field is seen, but still not good.

Split from #3572625: Calling $entity->getTranslatedField() results in an entity-sized memory leak where I found several other issues with circular references and static caching in the typed data system but this is something that can be done self-contained.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3574198

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

Status: Active » Needs review

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems pretty straight forward. Only comment maybe when we say it's set later we say where? But that may just be me so not holding it up.

alexpott’s picture

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

This is a nice find and the solution looks clean - we need to create with the parent because

       // Create the prototype without any value, but with initial parenting
       // so that constructors can set up the objects correctly.

Committed and pushed b3c46ac0610 to main and ded7281b87e to 11.x and 3f19f9d3a4a to 11.3.x. Thanks!

Backported to 11.3.x as a low risk performance fix.

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 3f19f9d3 on 11.3.x
    perf: #3574198 TypedDataManager prototypes should not include the parent...

  • alexpott committed ded7281b on 11.x
    perf: #3574198 TypedDataManager prototypes should not include the parent...

  • alexpott committed b3c46ac0 on main
    perf: #3574198 TypedDataManager prototypes should not include the parent...

Status: Fixed » Closed (fixed)

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