﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24590	Cache return value of `swappable_setting`	Marten Kenbeek	Markus Holtermann	"`Field.swappable_setting` is called very often during model rendering. It loops over all models until it finds a match or otherwise returns `None`. Most models aren't swappable, so in most cases it never breaks out of the loop.

This method should be cached to speed up rendering in migrations. The `Field` instances are constantly copied, so that's not a good place, but it always uses `django.apps.apps`. Moving this looping over models to `Apps.get_swappable_setting` and using an `lru_cache` speeds up rendering quite a bit.

Both `AUTH_USER_MODEL` and the models contained in the main `apps` instance should never change, except for testing scenario's. The cache should never have to be cleared in non-testing scenario's, which results in another very significant speed-up, for a total of about 35% faster rendering in my benchmarks. "	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
