[ZCM] [ZC] 1890/ 2 Comment "Minor TALES speedup"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Sat Sep 24 06:35:28 EDT 2005


Issue #1890 Update (Comment) "Minor TALES speedup"
 Status Accepted, Zope/feature+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/1890

==============================================================
= Comment - Entry #2 by ajung on Sep 24, 2005 6:35 am

Please merge for 2.8.2 and 2.7.8
________________________________________
= Request - Entry #1 by mcdonc on Sep 9, 2005 1:46 am

 Status: Pending => Accepted

 Supporters added: chrism


Uploaded:  "expression-render.diff"
 - http://www.zope.org/Collectors/Zope/1890/expression-render.diff/view
This patch to Products.PageTemplates.Expressions prevents its "render" function from being called for any "basic" Python type (avoiding the function call overhead and the very general sniffing logic in the render function body)... this is a minor speedup but it might save a few microseconds on every path expression call, and this can be important if path expression calls are part of the inner loop ofa rendering (which they oftetn are).  In one simple "real-world" page I observed that this patch reduced the function call count for "render" down from 57000 to 200 calls without any change in functionality.

The patch is inlined but also attached.  If no one complains, I will merge this patch into the Zope 2 HEAD (and the Zope 3 HEAD if I can figure out where its analogue is):

Index: Expressions.py
===================================================================
--- Expressions.py      (revision 38416)
+++ Expressions.py      (working copy)
@@ -156,7 +156,9 @@
         return 0
 
     def _eval(self, econtext,
-              isinstance=isinstance, StringType=type(''), render=render):
+              isinstance=isinstance,
+              BasicTypes=(str, unicode, dict, list, tuple, bool),
+              render=render):
         for expr in self._subexprs[:-1]:
             # Try all but the last subexpression, skipping undefined ones.
             try:
@@ -172,7 +174,7 @@
             if self._hybrid:
                 return ob
 
-        if self._name == 'nocall' or isinstance(ob, StringType):
+        if self._name == 'nocall' or isinstance(ob, BasicTypes):
             return ob
         # Return the rendered object
         return render(ob, econtext.vars)

==============================================================



More information about the Zope-Collector-Monitor mailing list