When displaying 10 nodes in English without translations, with interface and content language english, on a site with german and french enabled, it looks like getTranslation() is calling out to addTranslation() 20 times. That creates new entities, which is slow. It's 20x, because it calls getTranslation() for de and fr.

There seem to be two problems:
- Why is entity->getTranslation() called for de and fr, when I'm never interested in displaying that? Looks like field_invoke_method_multiple() is responsible for calling them, because it seems to call those methods for all languages. I have a feeling that #2019055: Switch from field-level language fallback to entity-level language fallback will possibly help here?

- The second problem is that creating new entities with entity_create() or the storage controller is very slow. Maybe that's also something that is already improved in the above issue, if not we should check if there's a faster way. Maybe we can make entity_create() and the default value process itself faster? Field objects could track if they already have default values, so that we could lazy-generate them when requested? Because doing it in advance creates a million field and field item objects, generates UUID's and so on.

Files: 
CommentFileSizeAuthor
#3 get-language-new-2090983-3.patch874 bytesBerdir
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 77,811 pass(es), 36 fail(s), and 32 exception(s).
[ View ]

Comments

yched’s picture

Yes, we need to refactor how widgets and formatters are invoked on the fields of an entity (field_attach_*() / field_invoke_method*())
But for that multilingual logic and language fallback needs to be sorted out.

jibran’s picture

Issue summary:View changes

There is no EntityNG in the core now.

Berdir’s picture

Status:Active» Needs review
StatusFileSize
new874 bytes
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 77,811 pass(es), 36 fail(s), and 32 exception(s).
[ View ]

Yeah, let's see if this still happens.

Status:Needs review» Needs work

The last submitted patch, 3: get-language-new-2090983-3.patch, failed testing.

yched’s picture

- addTranslation() is unnecessarly called :
field_invoke_method_multiple() is long gone now, not sure whether that's still the case ?

- addTranslation() is slow :
Yeah, posted a patch in #2382675: ContentEntityBase::addTranslation() should not fire hook_entity_create(), that removes the entity_create() - let's discuss there ?