This is probably true. Genshi's approach is different to the other
templating engines in that Genshi:
* first parses an XML template into a stream of events
* generates a stream of output events from the template
* renders the stream of output events to a new XML string
The down side to this approach is performance. The upside is that
templates which are valid XML can be expected to generate output that
is valid XML and problems like missing or broken end tags can be
picked up easily in the templates themselves.
Whether the reduced performance is worth this benefit will depend on
your use case. In my own current use case the performance requirements
are very moderate (parsing a few tens of text and XML files at process
launch) and the benefits of picking up problems early are clearly
worth a few fractions of a second in start-up time.
Other templating engines I've looked at generally work directly on the
XML as though it were plain text. This appears to be born out by the
analysis conducted into the talk you reference -- it's all about raw
string operations and concatenating output. In Genshi's case a
substantial part of the time is spend in processing event streams (if
I'm remembering correctly from my dive into Genshi benchmarking many
years ago).
The article doesn't actually appear to contain the details of the code
used to perform the Genshi benchmark so I can't comment in any detail
on whether they could have done better. The Trac developers on the
list will probably have a better idea of how to optimally use Genshi
for web templating than I do.
I am keen to see Genshi's performance improved, potentially even at
the expense of some sort of major code reworking if the speed increase
warranted it (say an order of magnitude or two decrease in the time a
real world application like Trac spends rendering templates). I don't
think it makes any sense to change Genshi's core philosophy of parsing
XML though -- if we did that it wouldn't be Genshi.
Schiavo
Simon
By the way, did someone already put cmlenz' ideas about a "Genshi v2"
somewhere on the wiki? If not, I can try to dig the mail he sent last
year to Trac-dev about this.
-- Christian
ElementTree would break the streaming model which would be a pity (and
I don't know off-hand whether it would be faster). I don't know lxml
well enough to comment on it's use.
Aside: Genshi provides some things (e.g. XPath) that I'm not sure will
ever be blindly fast in the general case.
Schiavo
Simon
I don't think I've seen them and a quick search of the Trac and Genshi
wikis and mailing lists didn't turn anything up. If you could dig them
up that would be much appreciated.
Schiavo
Simon
It's in, see
http://genshi.edgewall.org/wiki/GenshiPerformance#Ideasforimprovingtheperformance
Would be interesting to also provide some links to and summary of the
approaches started in the various experimental branches.
-- Christian
Agreed here. Has anyone else here looked at chameleon's genshi support? It's supposed to retain the XML-structure-based approach while producing speedup...
Cheers
David
Not to mention that IIRC in a lot of places in the code, the stream is
"linearized" with list(stream). Not using generators would also probably
make it easier to "grasp" what the code is actually doing ;-) I would be
very interested to see how a tree-based Genshi would behave. Another
wild idea: with an lxml.etree backend, the xpath operations could be
very fast...
>>>> timeit.timeit('list(i for i in xrange(10000))', number=10000)
> 7.5280599594116211
>>>> timeit.timeit('list([i for i in xrange(10000)])', number=10000)
> 6.1257951259613037
>>>> timeit.timeit('[i for i in xrange(10000)]', number=10000)
> 5.4970419406890869
>
> When you chose stream, were you concerned about speed, memory usage or
> text templates? I ask this because memory usage concern doesn't seem
> to be the case either since there is a cache and a template loader.
> I'd imagine most server-side usage of markup templates, or indeed even
> text templates would require caching of the data structure from
> parsing. However, text templates are really better stored as a
> sequence of string fragments and some transformation functions that
> take some Python data and output a string.
When I first learned about Genshi and its generator based
implementation, I thought it would be possible to stream the results,
e.g. by using chunked encoding transfer. However, we never really tried
to do it in Trac so I don't know whether this is actually possible or
not. I also don't know if this was part of the initial motivation for
using generators but it's a possibility.
> I think by using a stream as the fundamental data structure, you end
> up neither serving markup templates nor text templates right. Do
> people use Genshi as their text template engine at all? Can we just
> have a template engine that just do one thing only and does it well? I
> plan to experiment with a rewrite of Genshi in the coming couple of
> months that preserve as much Genshi markup template functionality as
> possible and be fast at the same time. I really like the idea of
> Genshi and I'd hate to see it stagnate. Any ideas, opinions and
> suggestions is welcome at this point.
Trac uses text templates in some places. Actually we initially used
"normal" xhtml templates to generate text but while possible, this
proved to be awkard to the point Christopher added TextTemplates. See
http://trac.edgewall.org/changeset/3730
-- Christian
I use it for generating email message body both in text and html format.
Regards,
Łukasz
Greetings,
I haven't followed Genshi much lately but I saw this post and just
wanted to add my two cents.
I like the text template feature as well. It's useful for generating
CSS, JavaScript, and the like. I'd hate to have to use a separate
template engine just for that, or use the aforementioned kludge of
wrapping the text in XML. And at any rate, it's not the culprit of
Genshi's performance issues and shouldn't be sacrificed.
Genshi is still far and away my favorite templating engine for Python.
The performance issues are not normally a problem for me, but they're
still a problem. I just hope it doesn't languish away completely.
Erik
Just to re-assure everyone, TextTemplates aren't going anywhere. Trac
and various Trac plugins use them and these form an important part of
Genshi's user base.
At my own day job, Genshi TextTemplates are used more extensively than
XML templates.
Schiavo
Simon
And thank you for spending your time on this -- I think all of us
(especially big users like Trac) are interested in improving Genshi's
performance.
Schiavo
Simon
So how do you guys like the approach taken by Kajiki?
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to gen...@googlegroups.com.
To unsubscribe from this group, send email to genshi+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
The benefits of a template system that truly understands XML is incredibly useful at development time,
Very cool. For other people's reference, the original posting explaining this is here:
http://groups.google.com/group/genshi/msg/56138ba479b81713
Nicholas, did you have get your code doing this up on bitbucket? :)
David
The benefits of a template system that truly understands XML is incredibly useful at development time,
--
Indeed. It's worth looking into and I think some people have tried some such things (vagueness...)
But if you build onto the genshi architecture significantly then your code all works around streams being processed through filters, which means it's not simple...