Superfast PageTemplates: Call for expertise
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
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 )
On Mon, Feb 17, 2003 at 03:30:26PM -0800, Dylan Reinhardt wrote:
At 03:24 PM 2/17/2003, Dylan Reinhardt wrote:
return ''.join(item for item in some_list])
Correction... that should be:
return ''.join([item for item in some_list])
or : return ''.join(some_list) if I don't miss anything. Jerome Alet
At 03:35 PM 2/17/2003, Jerome Alet wrote:
On Mon, Feb 17, 2003 at 03:30:26PM -0800, Dylan Reinhardt wrote:
At 03:24 PM 2/17/2003, Dylan Reinhardt wrote:
return ''.join(item for item in some_list])
Correction... that should be:
return ''.join([item for item in some_list])
or :
return ''.join(some_list)
if I don't miss anything.
Ah... true enough. That was too trivial an example to be meaningful. I should have written: ---------- # least efficient result = '' for item in some_list: result += do_something(item) return result # more efficient result = [] for item in some_list: result.append(do_something(item)) return ''.join(result) # most efficient ''.join([do_something(item) for item in some_list]) ---------- Dylan
On Mon, Feb 17, 2003 at 10:57:27PM +0000, 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.
I use the following code to produce HTML in my small python product OOPServer: def(self, ....): "docstring" ret=[] ret.append(self.standard_html_header()) ret.append(''' <form action="..."> %s %s ... </form>''' % (self.var1, self.var2)) ret.append(self.standard_html_footer()) return string.join(ret) thomas -- Thomas Guettler <guettli@thomas-guettler.de> http://www.thomas-guettler.de
On Tuesday 18 February 2003 19:50, Thomas Guettler wrote:
I use the following code to produce HTML in my small python product OOPServer:
Wispering: embedding HTML into the PyScript is ugly and it is Bad Idea TM, which is cames from the rubblish lister AKA Perl or [P]ornographic [H]ypertext [P]rocessor. P.S. I still use HTML in PyScripts but I'm wrong here. -- Regards, Bogdan The only way to learn a new programming language is by writing programs in it. - Brian Kernighan
On Tue, Feb 18, 2003 at 08:02:05PM +0200, Bo M. Maryniuck wrote:
On Tuesday 18 February 2003 19:50, Thomas Guettler wrote:
I use the following code to produce HTML in my small python product OOPServer:
Wispering: embedding HTML into the PyScript is ugly and it is Bad Idea TM, which is cames from the rubblish lister AKA Perl or [P]ornographic [H]ypertext [P]rocessor.
The goal to seperate content and logic is good and should always kept in mind, but somewhere you need to paint your data. That's why I have a base class which has nearly no HTML in it and a subclass which does render the data. thomas -- Thomas Guettler <guettli@thomas-guettler.de> http://www.thomas-guettler.de
Peter Bengtsson wrote at 2003-2-17 22:57 +0000:
... 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
DTML is much 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?
The slowest part for a PageTemplate is its parsing... Avoid doing it more than once.
Are there any particular constructions that are "bad" to do with TAL syntax/formatting?
I do not think so.
(I've heard that METAL is "slow" but they're difficult to avoid because of their great functionality)
I cannot confirm this. Someone started to code PageTemplates in C. I think, I read something about this in the "xml-sig" mailing list. A little less drastic would be to replace the "HTMLParser" and use, e.g. "sgmlop". Dieter
At 22:45 2003-02-18 +0100, Dieter Maurer wrote:
Peter Bengtsson wrote at 2003-2-17 22:57 +0000:
... 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
DTML is much faster...
Hmm. "much". Anybody has any numbers on this? (in my case it'd be too late now to change however)
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?
The slowest part for a PageTemplate is its parsing...
Parsing of what? I'm not an engineer but as I've understood it there are several different kinds of parsing to go from TAL to HTML.
Avoid doing it more than once.
Are there any particular constructions that are "bad" to do with TAL syntax/formatting?
I do not think so.
(I've heard that METAL is "slow" but they're difficult to avoid because of their great functionality)
I cannot confirm this.
Someone started to code PageTemplates in C. I think, I read something about this in the "xml-sig" mailing list.
A little less drastic would be to replace the "HTMLParser" and use, e.g. "sgmlop".
That sounds interesting but I'm not up for it myself. Peter
Dieter
FWIW, OpenPT has support for 'psyco', which is probably the easiest way to go. Haven't tested it yet but it sounds like a great idea. http://www.zope.org/Members/lalo/OpenPT/release_0.4 Stefan --On Montag, 17. Februar 2003 22:57 +0000 Peter Bengtsson <mail@peterbe.com> wrote:
My question is: How do I ease off the load on PageTemplate rendering?
-- Those who write software only for pay should go hurt some other field. /Erik Naggum/
participants (7)
-
Bo M. Maryniuck -
Dieter Maurer -
Dylan Reinhardt -
Jerome Alet -
Peter Bengtsson -
Stefan H. Holek -
Thomas Guettler