Opened 10 months ago
Last modified 10 months ago
#35241 closed Cleanup/optimization
Cache Model._meta.get_parent_list() — at Initial Version
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
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.