﻿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
27974	Degraded performance when rendering ChoiceField with lots of options and DEBUG=True	karyon	kapil garg	"One ChoiceField with 1k options took 6s instead of 0.5s after updating to django 1.11 with DEBUG=True.

apollo13 created a reduced test case:


{{{
    import django
    from django.conf import settings
     
    settings.configure(DEBUG=True)
    django.setup()
     
     
    from django.forms import Form, Select, ChoiceField
     
     
    class TestForm(Form):
        test = ChoiceField(widget=Select, choices=map(lambda x: (str(x), str(x)), range(1000)))
     
     
    print(TestForm())
}}}

and the following test


{{{
strace python3 test.py 2>&1|grep attr|wc
    1001    4004  120120
}}}

shows that [https://github.com/django/django/blob/master/django/forms/templates/django/forms/widgets/attrs.html this file] is read 1k times. It seems like the caching of the include tag inside loops does not work with nested includes. apollo13 investigated further.
"	Cleanup/optimization	closed	Template system	1.11	Normal	fixed			Accepted	1	0	0	0	0	0
