DDC-894: Performance improvement in AbstractQuery: Cache should be checked *before* flushing the unit of work, not after doing it #1111

Open
opened 2026-01-22 13:02:35 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 25, 2010).

Jira issue originally created by user dalvarez:

In /Doctrine/ORM/AbstractQuery.php, starting on line 490, the unit of work is flushed
if needed before processing the query:

    if ($this->_em->getUnitOfWork()->hasPendingInsertions()) {
        $this->_em->flush();
    }

If there is a subsequent cache hit, this turns out to be unnecessary later.

Checking the cache first and flushing the unit of work only on cache misses could increase
performance significantly in some scenarios (batch-jobs that are heavy on inserts) and does not cost a dime.

Otherwise the ORM is performing a significant amount of non-work, when we
could as well happily continue feeding the unit of work.

Originally created by @doctrinebot on GitHub (Nov 25, 2010). Jira issue originally created by user dalvarez: In /Doctrine/ORM/AbstractQuery.php, starting on line 490, the unit of work is flushed if needed before processing the query: ``` if ($this->_em->getUnitOfWork()->hasPendingInsertions()) { $this->_em->flush(); } ``` If there is a subsequent cache hit, this turns out to be unnecessary later. Checking the cache first and flushing the unit of work only on cache misses could increase performance significantly in some scenarios (batch-jobs that are heavy on inserts) and does not cost a dime. Otherwise the ORM is performing a significant amount of non-work, when we could as well happily continue feeding the unit of work.
admin added the Improvement label 2026-01-22 13:02:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1111