Optimize config entity import

Created on 10 February 2015, almost 10 years ago
Updated 13 July 2023, over 1 year ago

What I've done:
1) Load a JSON file containing data for 363 config entities (1 address_format, 362 subdivision config entities).
2) Start XHProf
3) Initialize each config entity, setSyncing(TRUE), save()
4) Stop XHProf

Attaching the xhprof. It clearly shows that significant time is spent invalidating cache tags (invalidateTagsOnSave()), and in ConfigEntityBase::preSave().

1) Would be great to find a way to invalidate cache tags only once per import.
This would require wrapping invalidateTagsOnSave() with a isSyncing() check, and having a way to invalidate the tags after the sync (a postSync() method?)

2) ConfigEntityBase::preSave() has this:

    // Ensure this entity's UUID does not exist with a different ID, regardless
    // of whether it's new or updated.
    $matching_entities = $storage->getQuery()
      ->condition('uuid', $this->uuid())
      ->execute();
    $matched_entity = reset($matching_entities);
    if (!empty($matched_entity) && ($matched_entity != $this->id()) && $matched_entity != $this->getOriginalId()) {
      throw new ConfigDuplicateUUIDException(String::format('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity)));
    }

This results in an entity query per save, taking up 25% of the total time. Ouch.
Alex Pott tells me that it should be safe to wrap at least that part with an isSyncing() check, but I haven't been able to confirm.

πŸ“Œ Task
Status

Closed: outdated

Version

9.5

Component
Configuration entityΒ  β†’

Last updated 3 days ago

Created by

πŸ‡·πŸ‡ΈSerbia bojanz

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I'm pretty sure this is outdated, cache tag invalidation will not re-invalidate the same cache tag more than once in a row and πŸ› ChainedFastBackend invalidates all items when cache tags are invalidated Fixed just landed, plus the install stuff mentioned above many years ago.

    On 2, I'm not 100% sure it's safe to skip the check, you could absolutely copy & paste a config entity manually, forget to change the UUID and try to import it. I think back then we didn't have config entity query indexes, so this should be much faster now.

Production build 0.71.5 2024