[Django] #35026: Improving perfromance of the apps registry `get_models()` method

12 views
Skip to first unread message

Django

unread,
Dec 8, 2023, 6:42:52 PM12/8/23
to django-...@googlegroups.com
#35026: Improving perfromance of the apps registry `get_models()` method
-------------------------------------+-------------------------------------
Reporter: Kamil | Owner: nobody
Paduszyński |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords: apps, models
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When studying the "applications" framework, I noticed that in
`django.apps.apps.get_models()` you mention in the comment.

> This method is performance-critical at least for Django's test suite.

If fact, the method involves a standard list extenstions. Has anyone
consider to implement this using `itertools.chain`?

{{{
#!python
from itertools import chain

# ...

def get_models(self, include_auto_created=False, include_swapped=False):
return chain(
*(app_config.get_models(include_auto_created, include_swapped)
for app_config in self.get_app_configs())
)
}}}

Shouldn't using a generator result in increased performance?

--
Ticket URL: <https://code.djangoproject.com/ticket/35026>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 9, 2023, 1:45:51 AM12/9/23
to django-...@googlegroups.com
#35026: Improving perfromance of the apps registry `get_models()` method
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: apps, models | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* status: new => closed
* resolution: => wontfix


Comment:

Hi,

Thanks for the suggestion, though using a generator here would break the
method (try it out to see why).

The comment you quoted is referring to the `@functools.cache` decorator &
any additional optimisations would be negligible here.

--
Ticket URL: <https://code.djangoproject.com/ticket/35026#comment:1>

Reply all
Reply to author
Forward
0 new messages