symfony4 – Performance doctrine manyToOne

I want improve performance of this code.
One entity have multiple criterion and criterion have multiple criteria value.
Here i insert criterion and criterion value and link to owner entity (product for example)

  public function createOrUpdateCriteriaIfEntityUpdated(
    HasCriterionInterface $ownerEntity,
    array $criteria,
    DateTime $dateImportStarted

) {
    $ownerEntity->setIsUpdated(true);
    if (!$ownerEntity->getIsUpdated()) {
        return false;
    }

    foreach ($criteria as $criterion) {
        $criterionValueEntity = $this->criterionValueRepository->createOrUpdate($criterion, $dateImportStarted);

        $ownerEntity->addCriterionValue($criterionValueEntity);
    }

    $this->em->persist($ownerEntity);

    return true;
}

   public function createOrUpdate(
    Criterion $criterion,
    DateTime $dateImport
): CriterionValue {
    
    // check critère si existe pas création sinon copntinue
    // check value si dans critère avec une boucle sur les value si non réation sinon update
    $criterionValue = $this->insertUpdateCriterion($criterion, $dateImport);

    return $criterionValue;
}

Here if criterion not found i create with value, else i look if value existe if not i create.
Before algo is very speed before, but when i has add multiple value for each criterion 🙁

public function insertUpdateCriterion(Criterion $criterion, DateTime $dateImport) : CriterionValue
{
    $criterionValueXml = $criterion->getCriterionValues()(0);
    $criterionDatabase = $this->getEntityManager()->getRepository(Criterion::class)
    ->findOneBy(('keyCriterion' => $criterion->getKeyCriterion()));

    if(!$criterionDatabase) {
        $criterion->setUpdatedAt($dateImport);
        $criterionValueXml->setUpdatedAt($dateImport);
        $this->getEntityManager()->persist($criterionValueXml);
        $this->getEntityManager()->persist($criterion);
        $this->getEntityManager()->flush();
        // need to insert in db for avoid duplicate criterion in other product or residences
        return $criterionValueXml;
    } 

    $criterionDatabase->setLabelCriterion($criterion->getLabelCriterion());
    $criterionDatabase->setUpdatedAt($dateImport);

    $criterionValues = $criterionDatabase->getCriterionValues();
    $comment = $criterionValueXml->getLabelCriterionValue();

    $criterionValueMatch = null;
    foreach($criterionValues as $criterionValue) {
        if($comment === $criterionValue->getLabelCriterionValue()) {
            $criterionValueMatch = $criterionValue;
            break;
        }
    }

    if(!$criterionValueMatch){
        $criterionValueXml->setCriterion($criterionDatabase);
        $this->getEntityManager()->persist($criterionValueXml);
        $criterionValueMatch = $criterionValueXml;
    }
    
    return $criterionValueMatch;
}

Thanks for you hep