= Google Summer of Code 2008 =
== The plan ==
* Reimplement XPath
* Add some kind of pre-rendering of parts that don't use variables
* Try compiling templates to Python bytecode
* Try adding some minor optimizations
== What has been done ==
=== XPath reimplementation ===
Current XPath implementation in Genshi is rather buggy (for example [http://genshi.edgewall.org/ticket/185]). I've rewritten it. Implemented algorithm works in O(qn) time, where q is length of XPath expression, n is number of stream events and O(qh) memory complexity, where h is height of document XML tree. It computes for every node which places of XPath expression does it match. O(qn) is pessimistic complexity, I think algorithm will work like O(n) in most cases (the worst case is when nearly every node matches to nearly every place of expression, which is quite rare).
Added also other implementations for simpler paths called strategies. Performance of new implementation in comparision with previous one can be checked [wiki:XPath-benchmark here].
=== Simple pre-rendering ===
py:optimize directive was introduced.
It marks subtree of this tag as optimizable - which means that rendering code inside can be omited and instead replaced by inserting cached one. In particular it cannot have any Python code that has side effects and cannot depend on variables.
Fragment of stream will be replaced by one event saying it represents this code. It will not be unpacked untill it is needed. Following cases "need" unpacking of fragment:
* matching tag inside optimized fragment; it also applies to first tag in
fragment so instead of
{{{
Some text inside with tags which processing could be costful,
but could be avoided by caching. Next paragraph. Some text inside with tags which processing could be costful,
but could be avoided by caching. Next paragraph.
It is divisible by three!
It's remainder when dividing by three is ${spell(var%3)}.
It is odd.
It is even.