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.