[Django] #35232: Cache Options.verbose_name_raw

19 views
Skip to first unread message

Django

unread,
Feb 18, 2024, 4:49:34 PM2/18/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Johnson |
Type: | Status: assigned
Cleanup/optimization |
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Another candidate for caching, like #35230, following the same system
check profiling.

The `Model._meta.verbose_name_raw` property returns the stringified
version of the `verbose_name` attribute whilst temporarily disabling
translations. It is only used in `django.contrib.auth` for creating
permission names.

Profiling the system checks on a project with 118 models revealed this
property was taking ~15% of the total runtime, taking 10ms across 420
calls. Turning it into a `cached_property` and adding a no-translation
fast path saves nearly all this cost, making it take <1ms across 105
calls.
--
Ticket URL: <https://code.djangoproject.com/ticket/35232>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 18, 2024, 4:51:30 PM2/18/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Adam Johnson:

Old description:

> Another candidate for caching, like #35230, following the same system
> check profiling.
>
> The `Model._meta.verbose_name_raw` property returns the stringified
> version of the `verbose_name` attribute whilst temporarily disabling
> translations. It is only used in `django.contrib.auth` for creating
> permission names.
>
> Profiling the system checks on a project with 118 models revealed this
> property was taking ~15% of the total runtime, taking 10ms across 420
> calls. Turning it into a `cached_property` and adding a no-translation
> fast path saves nearly all this cost, making it take <1ms across 105
> calls.

New description:

Another candidate for caching, like #35230, following the same system
check profiling.

The `Model._meta.verbose_name_raw` property returns the stringified
version of the `verbose_name` attribute whilst temporarily disabling
translations. It is only used in `django.contrib.auth` for creating
permission names.

I found this property was taking ~15 of the total runtime for system
checks on a project with 118 models. calls. Turning it into a
`cached_property` and adding a no-translation fast path saves nearly all
this cost, with the below results.

Before: 520 calls taking 10ms
After: 105 calls taking ~0ms

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

Django

unread,
Feb 18, 2024, 11:37:59 PM2/18/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
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

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

Django

unread,
Feb 18, 2024, 11:38:10 PM2/18/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
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 Mariusz Felisiak):

* stage: Unreviewed => Accepted

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

Django

unread,
Feb 19, 2024, 12:08:52 AM2/19/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
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):

* stage: Accepted => Ready for checkin

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

Django

unread,
Feb 19, 2024, 2:17:48 AM2/19/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
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 Mariusz Felisiak <felisiak.mariusz@…>):

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

Comment:

In [changeset:"f25d84f61a039d538bc742861f36579c704a310b" f25d84f]:
{{{#!CommitTicketReference repository=""
revision="f25d84f61a039d538bc742861f36579c704a310b"
Fixed #35232 -- Cached model's Options.verbose_name_raw.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35232#comment:5>

Django

unread,
Feb 20, 2024, 5:36:26 PM2/20/24
to django-...@googlegroups.com
#35232: Cache Options.verbose_name_raw
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
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
-------------------------------------+-------------------------------------
Description changed by Adam Johnson:

Old description:

> Another candidate for caching, like #35230, following the same system
> check profiling.
>
> The `Model._meta.verbose_name_raw` property returns the stringified
> version of the `verbose_name` attribute whilst temporarily disabling
> translations. It is only used in `django.contrib.auth` for creating
> permission names.
>
> I found this property was taking ~15 of the total runtime for system
> checks on a project with 118 models. calls. Turning it into a
> `cached_property` and adding a no-translation fast path saves nearly all
> this cost, with the below results.
>
> Before: 520 calls taking 10ms
> After: 105 calls taking ~0ms

New description:

Another candidate for caching, like #35230, following the same system
check profiling.

The `Model._meta.verbose_name_raw` property returns the stringified
version of the `verbose_name` attribute whilst temporarily disabling
translations. It is only used in `django.contrib.auth` for creating
permission names.

I found this property was taking ~15% of the total runtime for system
checks on a project with 118 models. calls. Turning it into a
`cached_property` and adding a no-translation fast path saves nearly all
this cost, with the below results.

Before: 520 calls taking 10ms
After: 105 calls taking ~0ms

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35232#comment:6>
Reply all
Reply to author
Forward
0 new messages