[Django] #35229: Prevent repeated checks of custom error handler URLs

17 views
Skip to first unread message

Django

unread,
Feb 18, 2024, 6:58:07 AM2/18/24
to django-...@googlegroups.com
#35229: Prevent repeated checks of custom error handler URLs
------------------------------------------------+--------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+--------------------------
In #29642 I added a system check for custom error handler URLs.

I looked at a profile for running the system checks on a project and found
this check function ran hundreds of times rather than once, totalling 1/4
of the time to run checks. The multiple runs occur because the check is
defined on `URLResolver`, of which exist in a tree structure. Moving the
check from `URLResolver` to a function in `django.core.checks.urls`
ensures it runs only once.

In the profiled project with 279 URLs, this takes the checks from ~24ms to
~21ms, a ~13% saving.
--
Ticket URL: <https://code.djangoproject.com/ticket/35229>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 18, 2024, 1:00:57 PM2/18/24
to django-...@googlegroups.com
#35229: Prevent repeated checks of custom error handler URLs
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted

Comment:

Do you think it might be worth adding
[https://github.com/django/djangobench/tree/master/djangobench/benchmarks
a check running benchmark] as well?
--
Ticket URL: <https://code.djangoproject.com/ticket/35229#comment:1>

Django

unread,
Feb 18, 2024, 4:02:50 PM2/18/24
to django-...@googlegroups.com
#35229: Prevent repeated checks of custom error handler URLs
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Adam Johnson):

It would be nice, but it’s very hard. Many of the performance problems
will only appear with scale, with many related models, URLs, etc. I think,
for now, it’s more fruitful to profile running checks on real projects.

By the way, this burst of optimization tickets is inspired by a Mastodon
discussion about disabling checks because of their slowness:
https://mastodon.social/@webology/111715052165307624 . I decided to
profile a client project yesterday and work on the clear hot spots.
--
Ticket URL: <https://code.djangoproject.com/ticket/35229#comment:2>

Django

unread,
Feb 18, 2024, 11:58:04 PM2/18/24
to django-...@googlegroups.com
#35229: Prevent repeated checks of custom error handler URLs
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
Severity: Normal | 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):

* owner: nobody => Adam Johnson
* stage: Accepted => Ready for checkin

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

Django

unread,
Feb 18, 2024, 11:58:46 PM2/18/24
to django-...@googlegroups.com
#35229: Prevent repeated checks of custom error handler URLs
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Core (System | Version: dev
checks) |
Severity: Normal | 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 GitHub <noreply@…>):

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

Comment:

In [changeset:"28a3fbe0048883fdd5cefd6ffecb88e351121891" 28a3fbe]:
{{{#!CommitTicketReference repository=""
revision="28a3fbe0048883fdd5cefd6ffecb88e351121891"
Fixed #35229 -- Made URL custom error handler check run once.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35229#comment:4>
Reply all
Reply to author
Forward
0 new messages