On Dec 2, 12:24 pm, Samuel <knipk... gmail.com> wrote:
> I am developing a CMS that uses Genshi and profiling
showed that a
> significant amount of time in the rendering process can
be contributed
> to Genshi generating the XHTML templates. In an attempt
to cut down
> this time I have tried to pickle() the result of
> TemplateLoader.load(), but this fails:
>
> TypeError: a class that defines __slots__ without
defining
> __getstate__ cannot be pickled
>
> Are there any options for caching this procedure?
Pickling the template objects won't actually save you time
in
rendering the templates, only in loading them. The
TemplateLoader
already caches the loaded templates internally, so as long
as your CMS
is running as a persistent process you won't be getting a
performance
boost from that. Although I have considered creating a
TemplateLoader
subclass that caches pickled templates to see if it provides
some
performance advantages at load time, so I might look into
making sure
those objects are pickleable.
I think the first thing to consider is HTTP caching headers.
Sending
Last-Modified headers based on the resources being viewed
and checking
If-Modified-Since on requests to send a 304 response if the
document
hasn't changed is going to give the biggest boost since you
can skip
the HTML generation entirely.
Also, one of the slowest features in Genshi is the py:match
templates. If you make heavy use of them take a look at the
"once"
and "recursive" attributes of py:match to see if
you can make use of
those, since that should give you some performance
increase:
http://genshi.edgewall.org/wiki/Documentatio
n/xml-templates.html#id5
If you're still needing to optimize after that you could
cache
portions of the rendered HTML. I haven't given much thought
to
handling this yet, but if you think you need it after some
other
optimizations come back and ask about it later.
-- Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|