mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Massive performance issue with setParameter() and DateTime* objects #6450
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @maks-rafalko on GitHub (Apr 17, 2020).
Bug Report
Related doc PR to warn users: https://github.com/doctrine/orm/pull/8114
Summary
Using
$qb->setParameter('date', new \DateTimeImmutable())without specifying 3rd argument (the type) leads to massive performance issues in long running processes.This is a follow up for https://github.com/doctrine/orm/issues/7527 (originally posted here https://github.com/doctrine/orm/pull/7471#discussion_r241949045)
Current behavior
As it's stated in the official docs (binding parameters to query)
So you can just pass a datetime object and it will work:
However, this leads to a) search this metadata in a cache, it fails and then b) load class metadata for every parameter of date types (e.g.
\DateTimeImmutable), and such metadata does not exist of course.Performance impact
We have a consumer that continuously reads data from the queue and executes queries, passing datetime object to
setParameter().Consumer is able to handle ~250 messages per secong, producing thousands of queries per second when it is fresh / is just started.
However, after some time there is a massive performance degradation (from 250/s, 230/s, ... 100/s, ... and so on). And this is exactly because of all the code that is executed just to load metadata for
\DateTimeImmutableclass which never exist).So there are thousands of cache misses, thrown but caught exceptions, attempts to load metadata.
After changing this
to this
we are no longer experiencing performance issues. After 30 minutes of working, consumer still handles ~250 records per second without degradation.
How to reproduce
Just create any entity with
datetime/datetime_immutablemapped property.Expected behavior
Expected behavior would be to not try loading metadata for datetime objects, but return the type immediately somewhere here:
8c259ea5cb/lib/Doctrine/ORM/Query.php (L411-L413)before trying to load metadata.
At this point,
$parameteralready havedatetimetype inside:@maks-rafalko commented on GitHub (Apr 18, 2020):
For maintainers: seems like this should be marked as
won't fixaccording to Marco's answers in https://github.com/doctrine/orm/pull/8115@bastnic commented on GitHub (Apr 19, 2020):
FYI, the root issue happens in doctrine/persistence, see https://github.com/doctrine/persistence/issues/96