#35102: Performance regression on Model.objects.count() between Django 4.2 and
5.0
-------------------------------------+-------------------------------------
Reporter: Anthony Shaw | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):
We could avoid cloning in two more places:
{{{#!diff
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index a79d66eb21..911d0c7848 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -422,6 +422,8 @@ class Query(BaseExpression):
return obj
def relabeled_clone(self, change_map):
+ if not change_map:
+ return self
clone = self.clone()
clone.change_aliases(change_map)
return clone
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 2f23a2932c..ae7a2a1224 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -225,6 +225,8 @@ class WhereNode(tree.Node):
return clone
def replace_expressions(self, replacements):
+ if not replacements:
+ return self
if replacement := replacements.get(self):
return replacement
clone = self.create(connector=self.connector,
negated=self.negated)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35102#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018cf7bcb2fb-444b9bd9-cd6b-4ff1-ae57-624d549a3855-000000%40eu-central-1.amazonses.com.