[Zope] Superfast PageTemplates: Call for expertise

Dylan Reinhardt zope@dylanreinhardt.com
Mon, 17 Feb 2003 15:24:32 -0800


The very easiest way to ease the load on ZPT is to use a caching proxy 
aggressively.

For pages that don't change much (or only change in response to url 
parameters) decent caching can make a huge difference.

There may also be ZPT-related techniques, but you'll see a lot more bang 
for your buck with caching.

In your product code, though, there may be a number of things you can 
do.  Some Python techniques are more resource-intensive than others and 
methods that get used a lot might be worth giving particular attention to.

For example, the following three code snips produce the same result but 
show markedly different resource usage.  Depending on how heavily they're 
called (or how big a string "item" is), it might make a significant difference.

---------
# least efficient
result = ''
for item in some_list:
    result += item
return result

# more efficient
result = []
for item in some_list:
    result.append(item)
return ''.join(result)

# most efficient
return ''.join(item for item in some_list])
---------

The Python Cookbook is a great place to find a number of these techniques 
and some discussion about what makes one work better than another.  For 
logic that provides values for your UI, the potential for improvement might 
be significant.

HTH

Dylan

At 02:57 PM 2/17/2003, Peter Bengtsson wrote:
>I just ran my python product for a spin with the ZopeProfiler (well done 
>Dieter Maurer!).
>My product uses PageTemplates (mostly through PageTemplateFile) and the 
>PageTemplate stuff really goes at the top of the CPU timing.
>I.e. the PageTemplate rendering is "slow". DTML is probably not faster and 
>I'm not "blaming" PageTemplates as such because I understand that they 
>have a lot of work to do.
>
>My question is: How do I ease off the load on PageTemplate rendering?
>
>What in TAL should generally be avoided, if possible, to gain that extra 
>performance?
>Are there any particular constructions that are "bad" to do with TAL 
>syntax/formatting?
>(I've heard that METAL is "slow" but they're difficult to avoid because of 
>their great functionality)
>
>I have already cheated and pushed some rendering down in the python class 
>which sometimes outputs HTML. I don't mind so much to do that in this case 
>because it's a pretty closed environment one could say.
>
>
>Peter
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://mail.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
>http://mail.zope.org/mailman/listinfo/zope-dev )