#35026 closed Cleanup/optimization (wontfix)

Improving perfromance of the apps registry `get_models()` method

Reported by: Kamil Paduszyński Owned by: nobody
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords: apps, models
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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?

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?

Change History (1)

comment:1 by David Sanders, 10 months ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top