Opened 9 months ago
Last modified 9 months ago
#35232 closed Cleanup/optimization
Cache Options.verbose_name_raw — at Initial Version
Reported by: | Adam Johnson | Owned by: | nobody |
---|---|---|---|
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
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.