#12008 was repurposed as a documentation improvement because the
current implementation is correct and just needs to be explained
better. As for the other two... I agree that consistency is important,
and that it would make sense (in a way) for ConstantIncludeNode to
either always raise or always silence, but that can definitely be done
without removing the CIN or hacking together some other way to get
similar compilation caching.

It's also worth mentioning that if TEMPLATE_DEBUG is set to ``True``,
the (non-constant) IncludeNode will raise an exception when it
*renders*, even though the Django docs clearly state that "render()
should never raise TemplateSyntaxError or any other exception. It
should fail silently, just as template filters should." If anything,
this is a more egregious error than ConstantIncludeNode's behavior.

That being said, whatever is decided, perhaps it could be applied to
the ExtendsNode as well? Right now, constant extends are loaded at the
same time as variable extends - handling constants differently could
give a similar performance boost there. In fact, there's a ticket open
to do just that: https://code.djangoproject.com/ticket/6586.

On Jun 3, 5:12 pm, Luke Plant <l.plant...@cantab.net> wrote:
> On 03/06/11 17:36, Aymeric Augustin wrote:
>
> > ConstantIncludeNode improves performance because it calls
> > django.template.loader.get_template() only once in __init__() and not
> > in each call to render().
>
> > get_template() invokes the template loading machinery to create a
> > compiled Template object, given a template path. If it's a
> > performance bottleneck, we can memoize its results. That will improve
> > performance of all template lookup operations, not only {% include
> > %}.
>
> We already have the cached template loader, and we don't want to invoke
> that kind of behaviour unless asked for (it's up to users to put it in
> their TEMPLATE_LOADERS settings), as it has significant memory overhead.
>
> I was thinking something simpler, like this:
>
> class IncludeNode(BaseIncludeNode):
>     def __init__(self, template_name, *args, **kwargs):
>         super(IncludeNode, self).__init__(*args, **kwargs)
>         self.template_name = template_name
>
>     def render(self, context):
>         try:
>             template_name = self.template_name.resolve(context)
>             if getattr(self, 'last_template_name', None) == \
>                     template_name:
>                 template = self.template
>             else:
>                 template = get_template(template_name)
>                 self.template = template
>                 self.last_template_name = template_name
>             return self.render_template(template, context)
>         except:
>             if settings.TEMPLATE_DEBUG:
>                 raise
>             return ''
>
> If I'm thinking correctly, that will keep the included template in
> memory only for the lifetime of the parent template, and will avoid
> loading it more than once if it is a static string and the include is in
> a loop.
>
> Luke
>
> --
> "Underachievement: The tallest blade of grass is the first to be
> cut by the lawnmower." (despair.com)
>
> Luke Plant ||http://lukeplant.me.uk/

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to