Drop the TEMPLATE_DEBUG setting

333 views
Skip to first unread message

Aymeric Augustin

unread,
Feb 15, 2015, 9:16:25 AM2/15/15
to django-d...@googlegroups.com
Hello,

During the multiple template engines refactor, I didn’t touch TEMPLATE_DEBUG.
The only purpose of this setting is to control whether Django stores the
information required to display stack traces for exceptions that occur while
rendering Django templatse. I think I should have deprecated it for the
following reasons.

1) Having the debug option of Django template engines default to DEBUG instead
of TEMPLATE_DEBUG will allow everyone to remove TEMPLATE_DEBUG = DEBUG from
their settings.

2) For the uncommon situation where one needs TEMPLATE_DEBUG != DEBUG, the new
TEMPLATES settings provides a solution:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'debug': True,
        },
    },
]

There should be only one way to do it and TEMPLATES beats TEMPLATE_DEBUG.

3) That will save developers of third-party backends from thinking about the
semantics of TEMPLATE_DEBUG vs. DEBUG. At best it's a pointless exercise and
at worst it will introduce inconsistencies. For example the maintainer of
django-jinja is about to diverge from Django in this regard:

I would like to update the DEP and make this change in Django 1.8 beta.

What do you think?

-- 
Aymeric.


Marc Tamlyn

unread,
Feb 15, 2015, 10:42:28 AM2/15/15
to django-d...@googlegroups.com

+1 to removing it

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/45CFE41A-16D5-4A6B-AF27-505C3E4BEA75%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Tino de Bruijn

unread,
Feb 15, 2015, 12:33:16 PM2/15/15
to django-d...@googlegroups.com

Enrique Paredes

unread,
Feb 15, 2015, 2:00:38 PM2/15/15
to django-d...@googlegroups.com, django-d...@googlegroups.com
+1

Last year I do an app to develop templates on the fly granting template_debug dump to some users (designers) and even in that escenario is looking good. Go for it.



On Sun, Feb 15, 2015 at 4:42 PM, Marc Tamlyn <marc....@gmail.com> wrote:

Paul Hallett

unread,
Feb 16, 2015, 3:41:54 AM2/16/15
to django-d...@googlegroups.com
+1!

Collin Anderson

unread,
Feb 16, 2015, 8:30:30 AM2/16/15
to django-d...@googlegroups.com
Hi,

Is there a reason to not always store the debug information? Performance? Why have two behaviors?

Thanks,
Collin


Aymeric Augustin

unread,
Feb 16, 2015, 8:51:42 AM2/16/15
to django-d...@googlegroups.com
2015-02-16 14:30 GMT+01:00 Collin Anderson <cmawe...@gmail.com>:
Is there a reason to not always store the debug information? Performance? Why have two behaviors?

Yes, I assume performance was the reason when this code was written, around 2005 or 2006.

I can't say if performance is still a concern after 10 years of hardware and software improvements.

Benchmarking the overhead of TEMPLATE_DEBUG = True would be interesting.

--
Aymeric.

aRkadeFR

unread,
Feb 16, 2015, 9:29:42 AM2/16/15
to django-d...@googlegroups.com
+1,

Thanks,

James Pic

unread,
Feb 16, 2015, 11:44:43 AM2/16/15
to django-d...@googlegroups.com
Sometimes I had to enable DEBUG and disable TEMPLATE_DEBUG in order to
get useful information about a crash. Am I the only one ?

Aymeric Augustin

unread,
Feb 16, 2015, 12:49:19 PM2/16/15
to django-d...@googlegroups.com
Just to clear a possible confusion — that will still be possible, but you’ll
have to do it differently once you start using the TEMPLATES setting:

DEBUG = True

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
# ...
'debug': False,
},
},
]

--
Aymeric.



> On 16 févr. 2015, at 17:44, James Pic <jame...@gmail.com> wrote:
>
> Sometimes I had to enable DEBUG and disable TEMPLATE_DEBUG in order to
> get useful information about a crash. Am I the only one ?
>
> --
> You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALC3Kac%2B8O74YxCB2xS2k4LbXR1ivGRYnqbZ9nn8eLk8Ph4vMQ%40mail.gmail.com.

Preston Timmons

unread,
Feb 17, 2015, 12:03:30 AM2/17/15
to django-d...@googlegroups.com
Here are some benchmarks I added here:


This is the cumulative time to do 1000 iterations:

Basic.do_init: 0.1423451900
BasicDebug.do_init: 0.1941769123
35% increase in parsing time

Basic.do_parse_complex: 1.2230978012
BasicDebug.do_parse_complex: 1.4190740585
15.5% increase in parsing time

FileSystem.do_get_template_complex: 1.4923889637
FileSystemDebug.do_get_template_complex: 1.7524909973
17.4% increase in parsing time

FileSystem.do_get_template_index: 0.5193221569
FileSystemDebug.do_get_template_index: 0.5603711605
9.8% increase

If my benchmarks are right, the increase is measurable, although probably not enough to notice in most usage of Django templates. Increasing parsing time isn't ideal, though, since that's where Django templates seems to spend most of their cpu time.

Curtis Maloney

unread,
Feb 18, 2015, 6:39:17 AM2/18/15
to django-d...@googlegroups.com
Just to chip in here... when TEMPLATE_DEBUG=True the template engine uses a substantially different Lexer, based on re.finditer() instead of re.split().

There are about 10 hooks in the Parser class, too, that exist almost exclusively to allow the DebugParser to change behavior.

If we always store the debug information [and do all the other parsing checks] it's likely the template parsing will become _faster_, just because of avoiding method calls.

For giggles, I'll run up a fork and see if I can get some meaningful results from Preston's very welcome template benchmark tool.

--
Curtis


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.

Preston Timmons

unread,
Mar 9, 2015, 4:40:44 PM3/9/15
to django-d...@googlegroups.com
Hey Curtis,

I was working to remove origin.reload and ended up with a fork that combines the debug implementation:


On a complex template with debug off I'm measuring about a 5% increase in template compile time compared to master. Turning debug on adds another 1% on top of that. That's a lot better than the current debug implementation.

80-90% of the additional time seems to be in the lexer, not the parser. This is due to the finditer loop being used to annotate the start and end position of each token in the template source.

Preston
Reply all
Reply to author
Forward
0 new messages