Cache Model._meta.get_parent_list()
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% (0.39ms) of the total runtime for system checks on a project with 118 models. After adding caching, it’s reduced to a negligible amount (<0.01ms).
get_parent_list()
is called in many other code paths, so caching will help all of those too.
Change History
(8)
Triage Stage: |
Unreviewed → Accepted
|
Patch needs improvement: |
set
|
Description: |
modified (diff)
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Thank you Adam! Do you have concrete benchmark numbers to share?