Generated with the help of an LLM.
Problem/Motivation
ContextDefinition::getDataDefinition() builds a new data definition on every call: it calls
createDataDefinition() or createListDataDefinition(), then copies the label, description, required flag and constraints onto it. Context::setContextValue() (for a raw value) and
Context::getContextData() (for the default value) call it when they create a context's typed data, and ContextDefinition::getSampleValues() calls it for isSatisfiedBy().
EntityContextDefinition overrides getSampleValues() and doesn't.
Since #3616328: Key the typed data prototype cache by the definition, not by root type and property path, typed data prototypes are keyed by the property or item definition object. When the parent definition is fresh, its child definitions usually are too, so they never hit the prototype cache: each call pays one create() per
child definition instead of cloning a prototype that is reused across the request. michaellander measured fresh definitions at about 40% slower in #3616328-28.
Before #3616328: Key the typed data prototype cache by the definition, not by root type and property path, these definitions shared one cache entry through the string key, which is also why they could get the wrong prototype.
The cost only applies where the child definitions are fresh as well:
- Multiple-value contexts:
createListDataDefinition()creates a new item definition every time. - Complex data types whose definition builds its own property definitions.
Entity contexts are not affected. EntityDataDefinition takes its property definitions from the entity field manager, which shares them, so they still hit. Scalar contexts have no children and don't use the prototype cache.

Steps to reproduce
TBD
Proposed resolution
Build the data definition once per context definition and return the same object on later calls:
- Store it in a protected property on
ContextDefinition. - Clear it in every setter that changes what it is built from:
setDataType(),setLabel(),setDescription(),setMultiple(),setRequired(),setConstraints()andaddConstraint().setDefaultValue()doesn't affect it. - Add a
__clone()that clears it, so a cloned context definition builds its own. - Leave it out of serialization, so plugin definition caches don't grow.
ContextDefinitionusesDependencySerializationTrait, so exclude the property in__sleep().
Remaining tasks
TBD
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3616328-core-context-definition.png | 271.29 KB | d34dman |
Comments
Comment #2
d34dman commentedComment #3
d34dman commentedComment #4
d34dman commentedComment #5
d34dman commentedComment #6
d34dman commentedComment #7
d34dman commented