There is an issue when using entity reference field in combination with autocomplete widget: when viewing a form using this widget with many items, performance degrades exponentially depending on item quantity.
Each time the single widget form is rendered, the \Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList::referencedEntities() method is called. This method in turn loads a revision of the entity. Unfortuntately? Drupal does not cache entity revisions, so what happens is for each field item (yet), all entity revisions referenced by that field are reloaded, E.g if there are 50 field items, there are 2500 (50*50) attempts to load from the database.
Ideally this would be fixed in core, where the autocomplete widget simply calls referencedEntities once. In addition caching revisions in #2620980: Add static and persistent caching to ContentEntityStorageBase::loadRevision() will also help.
At this time I think ERR should implement something similar to #3095329: Optimise entity reference autocomplete widget loading referencable entities, at least until this core issue is solved. Core has less motivation than ERR does to fix this. Ultimately should be fixed in core.
Comments
Comment #2
dpiPlease see #3095329: Optimise entity reference autocomplete widget loading referencable entities for more information, including a Blackfire profile with an ERR field.
Comment #3
berdirClosing as duplicate of #3098924: referencedEntities() causes data loss, patches welcome, should be pretty simple :)
Comment #4
berdirFWIW, using ERR with the default autocomplete widgt makes little sense, as that widget is not capable of referencing a revision, every edit will update to the default revision.