| 1 |
148 |
abw |
---------------------------------------------------------------------- |
| 2 |
|
|
Template::Stash::XS August 2001 |
| 3 |
|
|
---------------------------------------------------------------------- |
| 4 |
|
|
|
| 5 |
|
|
Introduction: |
| 6 |
|
|
|
| 7 |
|
|
* This is an XS implementation of the Template::Stash module, based |
| 8 |
|
|
in part upon work that Andy Wardley did late last year. It is |
| 9 |
|
|
an alternative version of the core Template::Stash methods ''get'' |
| 10 |
|
|
and ''set'' (the ones that should benefit most from a speedy C |
| 11 |
|
|
implementation), along with some virtual methods (like first, last, |
| 12 |
|
|
reverse, etc.) |
| 13 |
|
|
|
| 14 |
|
|
Doug Steinwand took the original code and made it into the fast and |
| 15 |
|
|
fully functional version you see here. Our appreciation is due to |
| 16 |
|
|
Ticketmaster, Inc. (http://www.ticketmaster.com/) who funded Doug's |
| 17 |
|
|
work on this to the benefit of us all. |
| 18 |
|
|
|
| 19 |
|
|
You can run the additional test script ''tt-bench.pl'' to see the |
| 20 |
|
|
improvement in speed. You may need to install the BSD::Resource |
| 21 |
|
|
module -- see http://search.cpan.org/search?dist=BSD-Resource |
| 22 |
|
|
|
| 23 |
|
|
perl tt-bench.pl |
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
Additional Notes: |
| 27 |
|
|
|
| 28 |
|
|
* Depending upon the size and content of a template, this version |
| 29 |
|
|
has about twice the speed of the original Template::Stash. |
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
* When a virtual method (like pop, push, nsort, sort etc.) has not |
| 33 |
|
|
been implemented in XS, it uses these hashrefs in Template::Stash |
| 34 |
|
|
package -- $HASH_OPS, $LIST_OPS, and $SCALAR_OPS -- to call perl |
| 35 |
|
|
subroutines that can do the work. |
| 36 |
|
|
|
| 37 |
|
|
|
| 38 |
|
|
* Using the ''reference'' feature of Template Toolkit -- like |
| 39 |
|
|
[% a = \foo %] -- leaks a large amount of memory. Enable the |
| 40 |
|
|
template code at the end of ''tt-bench.pl'' for a demonstration. |
| 41 |
|
|
(Note: This is a problem in the pure-perl version, too. Also, |
| 42 |
|
|
you'll need a platform that fully supports getrusage() -- FreeBSD |
| 43 |
|
|
and IRIX are two that should work. Otherwise, use a utility like |
| 44 |
|
|
''top''. ) |
| 45 |
|
|
|
| 46 |
|
|
|
| 47 |
|
|
* Although it passes all the tests that I've thrown at it, there may |
| 48 |
|
|
still be some problems and/or bugs. My primary goal was to mirror |
| 49 |
|
|
the behavior of the pure-perl version using XS. |
| 50 |
|
|
|
| 51 |
|
|
(NOTE: The XS Stash has subsequently been tested by numerous people |
| 52 |
|
|
on the Template Toolkit mailing list and everyone has reported 100% |
| 53 |
|
|
success and notable speedups - abw) |
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
|
|
* Profiling code can be enabled with ''#define TT_PERF_ENABLE'' in |
| 57 |
|
|
the Stash.xs source, but doing so hurts performance a bit. The |
| 58 |
|
|
results can be displayed by adding the line: |
| 59 |
|
|
|
| 60 |
|
|
print Template::Stash::XS::performance(1); |
| 61 |
|
|
|
| 62 |
|
|
to your code. Use 0 instead of 1 for a more compact display. |
| 63 |
|
|
|
| 64 |
|
|
|
| 65 |
|
|
* There's no need to try crazy compiler optimizations on this code, |
| 66 |
|
|
because a majority of time is spent inside Perl's functions. |
| 67 |
|
|
|
| 68 |
|
|
|