Hello All,

 I've recently developed an XS module for Template Toolkit that should
help improve performance.  I started with Andy's work from last year and
rewrote it to work with Template Toolkit version 2.04.  Amazingly, it
passes all tests in the ''make test'' suite.  Under ideal conditions,
it's about twice as fast as the original, pure-perl version.

 Attached you will find a tarball with the changes.  I've successfully
compiled it on FreeBSD 4.3 and RH Linux 6.2 using gcc 2.95.3 with the
''-O -Wall -ansi'' options; your mileage may vary.

 I want to thank TicketMaster, Inc. for giving me the opportunity to
develop, test and then release this code to the community.

 - doug


Template-Toolkit-2.04/xs/README

----------------------------------------------------------------------
 Template::Stash::XS                                      August 2001
----------------------------------------------------------------------

Introduction:

 * This is an XS implementation of the Template::Stash module, based
   in part upon work that Andy Wardley did late last year.  It is
   an alternative version of the core Template::Stash methods ''get'' 
   and ''set'' (the ones that should benefit most from a speedy C 
   implementation), along with some virtual methods (like first, last,
   reverse, etc.)


How to Build:

 1) Fetch and extract the Template-Toolkit-2.04.tar.gz and
    TT-2.04-XS.tar.gz tarballs:

        # mkdir work
        # cd work
        # tar zxf Template-Toolkit-2.04.tar.gz
        # tar zxf TT-2.04-XS.tar.gz


 2) Build Template Toolkit as usual, and answer ''yes'' to the XS 
    Stash questions. Note: Unless you answer ''yes' to the second 
    question, the ''make test'' step will not actually be testing the 
    XS version.  If so desired, use the PREFIX= option to install in 
    an alternative directory.  Also, you'll need a recent version of 
    File::Spec to pass all the tests -- see this link:
    http://search.cpan.org/search?dist=File-Spec

        # cd Template-Toolkit-2.04
        # perl Makefile.PL PREFIX=/somplace/else

          ... Do you want to build the XS Stash module? 
          ... Do you want to use the XS Stash for all Templates?

        # make
        # make test


 3) Run the additional test script ''tt-bench.pl'' to see the 
    improvement in speed. You may need to install the BSD::Resource
    module -- see http://search.cpan.org/search?dist=BSD-Resource

        # perl tt-bench.pl


 4) Optionally, install the new Template Toolkit:

        # make install


Additional Notes:

 * Depending upon the size and content of a template, this version
   has about twice the speed of the original Template::Stash.


 * When a virtual method (like pop, push, nsort, sort etc.) has not
   been implemented in XS, it uses these hashrefs in Template::Stash
   package -- $HASH_OPS, $LIST_OPS, and $SCALAR_OPS -- to call perl
   subroutines that can do the work.


 * Using the ''reference'' feature of Template Toolkit -- like
   [% a = \foo %] -- leaks a large amount of memory. Enable the
   template code at the end of ''tt-bench.pl'' for a demonstration.
   (Note: This is a problem in the pure-perl version, too.  Also,
   you'll need a platform that fully supports getrusage() -- FreeBSD
   and IRIX are two that should work. Otherwise, use a utility like
   ''top''. )


 * Although it passes all the tests that I've thrown at it, there may
   still be some problems and/or bugs.  My primary goal was to mirror
   the behavior of the pure-perl version using XS.


 * Profiling code can be enabled with ''#define TT_PERF_ENABLE'' in
   the Stash.xs source, but doing so hurts performance a bit.  The
   results can be displayed by adding the line:

          print Template::Stash::XS::performance(1);

   to your code. Use a 0 instead of 1 for a more compact display.


 * If you make changes to Stash.xs, simply run ''make'' and optionally
   ''make install'' in the Template-Toolkit-2.04 directory.
   Furthermore, there's no need to try crazy compiler optimizations on
   this code, because a majority of time is spent inside Perl's
   functions.


 * Here's the manifest for the TT-2.04-XS.tar.gz package:

        Template-Toolkit-2.04/Makefile.PL
        Template-Toolkit-2.04/tt-bench.pl
        Template-Toolkit-2.04/lib/Template/Stash/XS.pm
        Template-Toolkit-2.04/t/stash-xs.t
        Template-Toolkit-2.04/xs/MANIFEST
        Template-Toolkit-2.04/xs/Makefile.PL
        Template-Toolkit-2.04/xs/README
        Template-Toolkit-2.04/xs/Stash.xs

Attachment: TT-2.04-XS.tar.gz
Description: GNU Zip compressed data

Reply via email to