#22086: Building of template nodelist inside cache blocks
--------------------------------------+------------------------------------
     Reporter:  HenrikOssipoff        |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Template system       |                  Version:  1.6
     Severity:  Normal                |               Resolution:
     Keywords:  template, cache       |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by HenrikOssipoff):

 You are absolutely right - at some point the cached node will need to be
 rendered, at which point the nodelist inside the cached block will become
 irrelevant - it will just load whatever is cached instead and ignore the
 underlying tree.
 But the tree still exists under the cached block until that point, and
 that seems to be the performance bottleneck we're experiencing, the fact
 that the tree needs to be built.

 I've attached two of our template files to perhaps give a better
 understanding. `menu_dk.html` is being included from our `base.html`
 template, which forms the basis of all of our other templates. If you look
 at that template, it's mostly just a cache block with other files included
 within that cache block. So far so good.
 Then comes one of the included files, `games.html`. If you look through a
 bit of that, you see that nearly everything in it is custom template tags,
 namely `url-translate` and `facet-translate`. We know this is an ugly way
 to do it, but it's needed for our application at the moment - each of
 these tags generates a node that will, in their `render()`, do a look-up
 in our product catalogue to find the correct translation for whatever
 language we're showing. No code of value is in the nodes' `__init__`.

 From my findings, it is the sheer number of nodes in the sub-tree of nodes
 inside the cache block that makes the template slow, even when the whole
 block is in fact cached. Sure, the nodes aren't rendered, but they still
 exist in the tree, causing up to 100ms to 200ms of extra time for our
 application.

 In our particular case, it seems it would be an optimization if we could
 somehow tell the cache block to only built its inside nodelist if there
 didn't exist a valid cache for the block. In most cases, this check would
 likely take up more time than just building the tree, while in extreme
 cases of alot of nodes inside the cache block, it would be an
 optimization.

 Hope this made it more clear, otherwise I'll be happy to provide more code
 if need be.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22086#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.271f9614c57dcb93560d16944f617078%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to