[Django] #34580: Performance regession in SQLCompiler

19 views
Skip to first unread message

Django

unread,
May 20, 2023, 3:58:58 AM5/20/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-----------------------------------------+------------------------
Reporter: David Smith | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Looking at the Django's [https://django.github.io/django-asv/ ASV
benchmarks ] the [https://django.github.io/django-
asv/#query_benchmarks.query_count.benchmark.QueryCount.time_query_count
query count ] and [https://django.github.io/django-
asv/#query_benchmarks.query_aggregate.benchmark.QueryAggr.time_aggregate
aggregate ] benchmarks show performance regressions.

Rough orders of magnitude are
Query Count 1.257ms -> 1.849ms 47% Increase
Aggregate 0.882ms -> 1.238ms 40% Increase

I managed to bisect the regression to this commit
https://github.com/django/django/commit/278881e3 |
278881e37619278789942513916acafaa88d26f3

--
Ticket URL: <https://code.djangoproject.com/ticket/34580>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 21, 2023, 11:31:07 AM5/21/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------

Reporter: David Smith | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* cc: Simon Charette (added)
* type: Uncategorized => Cleanup/optimization
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for the report, can you point at the exact test definition that
regressed otherwise it's quite hard to confirm what actually got slower

Is this

[https://github.com/django/djangobench/blob/4c88fa81c4d7618604ae51e07c03c23f6734c2e6/djangobench/benchmarks/query_count/benchmark.py
query_count] and
[https://github.com/django/djangobench/blob/4c88fa81c4d7618604ae51e07c03c23f6734c2e6/djangobench/benchmarks/query_aggregate/benchmark.py#L12
aggregate]?

If that's the case then I'm surprised this particular commit caused a
regression in these `Count` tests as none of them make use or ordering. If
that's truly the culprit then it's likely only a matter of not generating
`selected_exprs` if there is no `ordering` in the first place.

--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:1>

Django

unread,
May 21, 2023, 12:58:10 PM5/21/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Smith):

I attempted to see if the benchmark workflow could detect the changes from
the propose patch in [https://github.com/django/django/pull/16882 PR ].
Unfortunately it could not.

However, running locally I can see a performance improvement in the region
of 20-30% from the proposed change. I was able to repeat this, and see a
similar improvement a second time.

{{{
before after ratio
[ca5d3c99] [2aa6996a]
<form_docs> <SQLCompiler>
- 1.83±0.01ms 1.41±0.01ms 0.77
query_benchmarks.query_exists.benchmark.QueryExists.time_query_exists
- 874±2μs 621±8μs 0.71
query_benchmarks.query_aggregate.benchmark.QueryAggr.time_aggregate
- 1.35±0.02ms 905±4μs 0.67
query_benchmarks.query_count.benchmark.QueryCount.time_query_count
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:2>

Django

unread,
May 21, 2023, 7:15:23 PM5/21/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 4.2
(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
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:3>

Django

unread,
May 21, 2023, 11:51:06 PM5/21/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: David
Type: | Smith
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => David Smith
* status: new => assigned
* severity: Normal => Release blocker
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:4>

Django

unread,
May 21, 2023, 11:53:15 PM5/21/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: David
Type: | Smith
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:5>

Django

unread,
May 22, 2023, 1:57:07 AM5/22/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: David
Type: | Smith
Cleanup/optimization | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"98f6ada0e2058d67d91fb6c16482411ec2ca0967" 98f6ada]:
{{{
#!CommitTicketReference repository=""
revision="98f6ada0e2058d67d91fb6c16482411ec2ca0967"
Fixed #34580 -- Avoided unnecessary computation of selected expressions in
SQLCompiler.

Performance regression in 278881e37619278789942513916acafaa88d26f3.

Co-authored-by: David Smith <smi...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:6>

Django

unread,
May 22, 2023, 1:57:26 AM5/22/23
to django-...@googlegroups.com
#34580: Performance regession in SQLCompiler
-------------------------------------+-------------------------------------
Reporter: David Smith | Owner: David
Type: | Smith
Cleanup/optimization | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e1c00f8b361bf89deb68733bbc5189734bbcd6b5" e1c00f8]:
{{{
#!CommitTicketReference repository=""
revision="e1c00f8b361bf89deb68733bbc5189734bbcd6b5"
[4.2.x] Fixed #34580 -- Avoided unnecessary computation of selected
expressions in SQLCompiler.

Performance regression in 278881e37619278789942513916acafaa88d26f3.

Co-authored-by: David Smith <smi...@gmail.com>

Backport of 98f6ada0e2058d67d91fb6c16482411ec2ca0967 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34580#comment:7>

Reply all
Reply to author
Forward
0 new messages