#35241: Cache Model._meta.get_parent_list() -------------------------------------+------------------------------------- Reporter: Adam Johnson | Owner: Adam Type: | Johnson Cleanup/optimization | Status: assigned Component: Database layer | Version: dev (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Old 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. New 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% (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. -- Comment (by Adam Johnson): I added concrete numbers to the description. -- Ticket URL: <https://code.djangoproject.com/ticket/35241#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018dd2ac3a52-1199309e-2551-4298-aa8f-3917094917ad-000000%40eu-central-1.amazonses.com.