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

Closed
opened 2026-01-22 13:02:39 +01:00 by admin · 2 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:39 +01:00
admin closed this issue 2026-01-22 13:02:39 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2010):

Comment created by @beberlei:

We removed the flush inside AbstractQuery and clearly documented this behavior in the docs. If you need a clean query, you have to call EM->flush() yourself, explicit behavior is better in this case.

The cache issue then becomes a non-issue.

@doctrinebot commented on GitHub (Dec 27, 2010): Comment created by @beberlei: We removed the flush inside AbstractQuery and clearly documented this behavior in the docs. If you need a clean query, you have to call EM->flush() yourself, explicit behavior is better in this case. The cache issue then becomes a non-issue.
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Dec 27, 2010): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1112