Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#35232 closed Cleanup/optimization (fixed)

Cache Options.verbose_name_raw — at Version 6

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam Johnson)

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

Change History (6)

comment:1 by Adam Johnson, 9 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 9 months ago

Owner: changed from nobody to Adam Johnson

comment:3 by Mariusz Felisiak, 9 months ago

Triage Stage: UnreviewedAccepted

comment:4 by Mariusz Felisiak, 9 months ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 9 months ago

Resolution: fixed
Status: assignedclosed

In f25d84f:

Fixed #35232 -- Cached model's Options.verbose_name_raw.

comment:6 by Adam Johnson, 9 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top