Edgewall Software

Changes between Version 40 and Version 41 of GenshiPerformance


Ignore:
Timestamp:
Mar 21, 2013, 10:19:00 PM (11 years ago)
Author:
hodgestar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GenshiPerformance

    v40 v41  
    11= Performance of the Genshi Template Engine =
    22
    3 The directory [source:/trunk/examples/bench/ examples/bench] has some very simple benchmarks to compare the performance of Genshi to other template engines.
     3The directory [source:/trunk/examples/bench/ examples/bench] has some very simple benchmarks.
    44
    55  ''It should be noted that text-based template engines generally have a '''lot''' less work to do than XML-based ones, simply because their functionality is limited to processing text as opposed to processing markup.''
     6
    67
    78== `basic` benchmark ==
     
    910The [source:/trunk/examples/bench/basic.py basic.py] benchmark is based on a relatively simple template that includes a lot of the common templating constructs, such as includes/inheritance, looping, conditionals, macros, etc.
    1011
    11 All tests run under Python 2.4.4 on Mac OS X (iMac 2.16 GHz).
     12All tests run under on Ubuntu 12.10 (Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz).
    1213
    13 || '''Template Engine''' || '''Rendering time (less is better)''' || '''Notes''' ||
    14 || Genshi || 2.65 ms || Genshi markup template ||
    15 || Genshi (Text) || 0.98 ms || The text-based template engine included with Genshi ||
     14|| '''Template Engine''' || '''Python version''' || '''Rendering time (less is better)''' || '''Notes''' ||
     15||||||||||
     16|| Genshi || CPython 2.7 || 1.06 ms || Genshi markup template ||
     17|| Genshi_text || CPython 2.7 || 0.36 ms || The text-based template engine included with Genshi ||
     18||||||||||
     19|| Genshi || CPython 3.3 || 1.41 ms || Genshi markup template ||
     20|| Genshi_text || CPython 3.3 || 0.49 ms || The text-based template engine included with Genshi ||
     21||||||||||
     22|| Genshi || PyPy 2.7 || 2.42 ms || Genshi markup template ||
     23|| Genshi_text || PyPy 2.7 || 0.50 ms || The text-based template engine included with Genshi ||
     24
     25{{{
     26#!comment
    1627|| [http://kid-templating.org/ Kid] || 6.16 ms || Kid templates are compiled to Python byte-code. The cElementTree implementation was used for this test, although using the Python implementation doesn't appear to make a significant difference. ||
    1728|| [http://www.djangoproject.com/documentation/templates/ Django] || 1.38 ms || Text-based template engine that comes with the [http://www.djangoproject.com/ Django] framework. ||
     
    1930|| [http://www.makotemplates.org/ Mako] || 0.31 ms || Text-based template engine written in Python ||
    2031|| [http://www.owlfish.com/software/simpleTAL/ SimpleTAL] || 2.84 ms || Another XML-based template engine written in Python, based on the [http://www.zope.org/ Zope] template engine (TAL). ||
     32}}}
    2133
    22 The test template is rather simple right now and doesn't make much use of the advanced features provided by either Genshi or Kid, because then it would be impossible to implement an equivalent template using other template languages.
     34The test template is rather simple right now and doesn't make much use of the advanced features provided by either Genshi, because then it would be impossible to implement an equivalent template using other template languages.
     35
    2336
    2437== `bigtable` benchmark ==
     
    2639The [source:/trunk/examples/bench/bigtable.py bigtable.py] benchmark renders a large HTML table (with 1000 rows and 10 columns) in two nested loops, where each cell contains a variable reference. This basically measures the raw throughput of the template engine, while not using any advanced features.
    2740
    28 || '''Template Engine''' || '''Rendering time (less is better)''' || '''Notes''' ||
    29 || Genshi || 390 ms || Genshi markup template ||
    30 || Genshi (Text) || 197 ms || The text-based template engine included with Genshi ||
     41|| '''Template Engine''' || '''Python version''' || '''Rendering time (less is better)''' || '''Notes''' ||
     42||||||||||
     43|| Genshi tag builder || CPython 2.7 || 192 ms || ||
     44|| Genshi template || CPython 2.7 || 107 ms || ||
     45|| Genshi text template || CPython 2.7 || 74 ms || ||
     46|| Genshi template + tag builder || CPython 2.7 || 212 ms || ||
     47||||||||||
     48|| Genshi tag builder || CPython 3.3 || 266 ms || ||
     49|| Genshi template || CPython 3.3 || 134 ms || ||
     50|| Genshi text template || CPython 3.3 || 95 ms || ||
     51|| Genshi template + tag builder || CPython 3.3 || 287 ms || ||
     52||||||||||
     53|| Genshi tag builder || !PyPy 2.7 || 103 ms || ||
     54|| Genshi template || !PyPy 2.7 || 74 ms || ||
     55|| Genshi text template || !PyPy 2.7 || 43 ms || ||
     56|| Genshi template + tag builder || !PyPy 2.7 || 106 ms || ||
     57
     58{{{
     59#!comment
    3160|| [http://kid-templating.org/ Kid] || 1101 ms || ||
    3261|| [http://www.djangoproject.com/documentation/templates/ Django] || 474 ms || ||
     
    3766
    3867''Note that both ET and cET are using Python code for serialization.''
     68}}}
    3969
    40 == Another benchmark ==
    41 
    42 There's another simple benchmark in the Genshi repository: [source:/trunk/examples/basic/ examples/basic]. That example is however only implemented for Genshi and Kid, as it makes use of features not found in other template languages. Here are the numbers:
    43 
    44 || '''Template Engine''' || '''Rendering time (less is better)''' || '''Notes''' ||
    45 || Genshi || 2.89 ms || ||
    46 || [http://kid-templating.org/ Kid] || 6.93 ms || ||
    4770
    4871== Ideas for improving the performance ==
    4972
    50 In a [http://groups.google.com/group/trac-dev/msg/fe3bfd51a880a3e7 mail on Trac-dev] in April 2010, Christopher Lenz wrote the following, in reply to Eirik Schwenke:
    51 {{{
    52 #!div style="margin: 1em 2em; border: 2px solid #ccc"
    53 > Anyway, I think there are three seperate issues, that all warrant discussion:
    54 > >
    55 > > a) Is the speed of genshi doomed due to genshis design? And if so,
    56 > >    should we for *speed reasons* give up on genshi ?
    57 The current design is inefficient in a number of ways. The whole design choice that everything is streamed through the pipeline event by event (SAX-style) using Python generators has proved to be rather poor. That match templates are processed at render time makes their use quite expensive, and it certainly doesn't scale to a larger number of match templates.
    58 
    59 It would be possible to move Genshi towards a more efficient implementation by:
     73See Christopher Lenz's [http://groups.google.com/group/trac-dev/msg/fe3bfd51a880a3e7 mail to Trac-dev] for a more detailed discussion. Ideas for performance improvements:
    6074
    6175 * Dropping support for dynamic XInclude tags, i.e. Genshi would need to know what gets included at parse time.
     
    6579 * Etc.
    6680
    67 It would still not be in the same league as highly optimized text template engine such as Mako or Jinja2, but I think it would be totally usable. As a point of reference, Genshi trunk is in some cases actually faster than Django templates in raw throughput when you don't use things like match templates (last time I tested at least), and lots of sites use Django templates. I think that doing the above changes would make Genshi consistently faster than Django templates (at least the current implementation).
     81Many of these represent substantial changes an would effectively result in Genshi2.
    6882
    69 But those changes also require a lot of work, and would obviously take away some features people (including Trac and Trac plugins) may have been relying on. It'd basically be Genshi2 ;)
    70 
    71 > > c) Does genshi's stream-filters provide enough of an advandage
    72 > >    to push for b) over a) ?
    73 Not sure. Stream filtering is used for a couple things, most importantly form filling and localization. Removing stream filtering leaves two alternative ways to achieve these (and similar) tasks:
    74  * post-process the generated output (parse/transform)
    75  * take care of everything right in the template, i.e. manually fill in form values, gettext() all strings, etc.
    76 
    77 Stream filters are nice in that they let you implement "cross-cutting concerns" outside of the templates, and doesn't require a post-processing stage. Whether that's worth the cost I don't know.
    78 }}}
     83Currently Genshi is roughly twice as fast on PyPy as on CPython 2.7.
    7984
    8085== See Also ==