#3453: resolve_variable usage leads to redundant work
-----------------------------------------------+----------------------------
Reporter: Brian Harring <[EMAIL PROTECTED]> | Owner: adrian
Status: new | Component: Template system
Version: SVN | Keywords:
Stage: Unreviewed | Has_patch: 1
-----------------------------------------------+----------------------------
Yet more refactoring ;)
resolve_variable does a chunk of setup work for each invocation, checking
for if the variable is a number, checking if its quoted (thus exempted
from lookup rules), and finally splitting of the variable into it's
component parts. The issue is that this work is utterly redundant the
second time an attempt is made to resolve the variable- for loops for
example.
This patch splits out a Variable class which does the common setup work up
once in init, with a resolve method to do the actual resolution against a
context. The actual resolve is still a good chunk of time, but for my
particular usage scenario (3 level deep for loop being the main cost),
this shaves just shy of 25% of the runtime off via killing the redundant
work.
From a backwards compatibility standpoint, there isn't any issue-
resolve_variable just becomes
{{{
def resolve_variable(arg, context):
return Variable(arg).resolve(context)
}}}
which admittedly will be slightly slower then whats in place now for
simple lookups- this is offset by the greater efficiency of Variable usage
within default tags/templates, and via killing off a quadratic op in
resolve_variable- currently, it splits the arg, then does poplefts on the
list.
Problem there is that python lists are literal arrays; you delete the
first item, every item after has to be moved one to the left, thus quad in
execution. Fortunately var depth isn't usually deep enough for it to rear
its head.
--
Ticket URL: <http://code.djangoproject.com/ticket/3453>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---