#35241: Cache Model._meta.get_parent_list()
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: Adam Johnson
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 and #35232, following the same
system check profiling.
`Model._meta.get_parent_list()` computes the flattened list of ancestor
models by MRO. This list is immutable, deterministic, and recursively
constructed through the inheritance hierarchy. These properties make it a
prime candidate for caching.
I found this method was taking ~1% of the total runtime for system checks
on a project with 118 models. After adding caching, it’s reduced to a
negligible amount.
`get_parent_list()` is called in many other code paths, so caching will
help all of those too.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35241>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.