Problem/Motivation
It takes anywhere between 10-15ms to create a dummy entity, this is 10-15 times as long as loading one.
See #2471218: Dummy comment entity necessary for building comment form is expensive to build and #2479529-38: \Drupal\user\ContextProvider\CurrentUserContext::onBlockActiveContext() loads the anonymous user and #2552873: node/1 flamegraphs.
Proposed resolution
Look into either or both of:
1. Optimizing the process - this would more or less mean optimizing typed data.
2. Caching the entity/default values somewhere, so that for example rendering the comment form can re-use the same dummy entity each time.
Comments
Comment #2
catchComment #3
dawehnerWe should first check whether these numbers are caused by the actual process of initializing the entity or just by the fact that we have to load the various entity caches.
Comment #4
catchWhen I looked at it before, a lot of the cost was loading entity and field info caches - we don't access field info when loading a real entity and a couple of recent patches made it so that the page node type (for example) can be loaded, access checked and rendered without touching them.
So a persistently cached 'empty/default entity' ought to cut all of that out.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman at Acquia commentedOK, thats a good start. Some more questions:
Comment #6
BerdirThe main reason for this is initializing all fields with default values. We have no API for creating an empty entity object, only one with default values applied.
That's not cacheable. E.g., the UUID needs to be generated differently each time.
Instead, what we need is an API to create an empty entity object, which should be a lot faster. We have various issues for that, for example #1867228: Make EntityTypeManager provide an entity factory.
I think we should close this as a duplicate of that.
Comment #15
catchSix years later closing as duplicate of #1867228: Make EntityTypeManager provide an entity factory.