An item I ran into lately is a desire to squeeze even more performance out of H::T. Since I'm in a mod_perl environment, I typically load up a handfull of templates and then render them over and over again. To help this out, I built a version of H::T that cross-compiles the stack-based code into an anonymous sub(), and then eval's it to render the output. I've found this to offer a significant performance benefit over stock H::T.
One thing to know about my environment is that I'm on a Win32 platform (currently). Therefore, H::T::JIT wasn't an option for me.
Anyway, here's some performance numbers. This is a simple program that creates a template, loads a bunch of parameters, and then renders it 100 times. I've included the dprofpp results for H::T and H::T::Compile.
HTML::Template
--------------
C:\Test>perl -d:DProf foo.pl
--------------
C:\Test>perl -d:DProf foo.pl
C:\Test>dprofpp
Total Elapsed Time = 152.7336 Seconds
User+System Time = 151.4206 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
86.7 131.4 155.75 11400 0.0115 0.0137 HTML::Template::output
11.8 17.92 17.921 539401 0.0000 0.0000 HTML::Template::param
1.56 2.369 2.369 52900 0.0000 0.0000 HTML::Template::_globalize_vars
1.33 2.020 2.020 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
0.66 1.000 1.000 11300 0.0001 0.0001 HTML::Template::clear_params
0.48 0.722 151.05 1200 0.0006 0.1259 HTML::Template::LOOP::output
0.24 0.357 0.392 1 0.3567 0.3925 HTML::Template::_parse
0.11 0.169 0.169 4900 0.0000 0.0000 HTML::Template::URLESCAPE::escape
0.10 0.144 0.144 5800 0.0000 0.0000 HTML::Template::ESCAPE::escape
0.05 0.070 0.139 1 0.0699 0.1392 main::BEGIN
0.03 0.050 0.069 9 0.0055 0.0077 HTML::Template::BEGIN
0.01 0.020 0.020 1 0.0200 0.0200 HTML::Template::_init_template
0.01 0.017 0.017 577 0.0000 0.0000 HTML::Template::VAR::new
0.01 0.010 0.010 2 0.0050 0.0050 DynaLoader::BEGIN
0.01 0.010 0.010 3 0.0033 0.0033 vars::BEGIN
Total Elapsed Time = 152.7336 Seconds
User+System Time = 151.4206 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
86.7 131.4 155.75 11400 0.0115 0.0137 HTML::Template::output
11.8 17.92 17.921 539401 0.0000 0.0000 HTML::Template::param
1.56 2.369 2.369 52900 0.0000 0.0000 HTML::Template::_globalize_vars
1.33 2.020 2.020 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
0.66 1.000 1.000 11300 0.0001 0.0001 HTML::Template::clear_params
0.48 0.722 151.05 1200 0.0006 0.1259 HTML::Template::LOOP::output
0.24 0.357 0.392 1 0.3567 0.3925 HTML::Template::_parse
0.11 0.169 0.169 4900 0.0000 0.0000 HTML::Template::URLESCAPE::escape
0.10 0.144 0.144 5800 0.0000 0.0000 HTML::Template::ESCAPE::escape
0.05 0.070 0.139 1 0.0699 0.1392 main::BEGIN
0.03 0.050 0.069 9 0.0055 0.0077 HTML::Template::BEGIN
0.01 0.020 0.020 1 0.0200 0.0200 HTML::Template::_init_template
0.01 0.017 0.017 577 0.0000 0.0000 HTML::Template::VAR::new
0.01 0.010 0.010 2 0.0050 0.0050 DynaLoader::BEGIN
0.01 0.010 0.010 3 0.0033 0.0033 vars::BEGIN
C:\Test>dprofpp -r
Total Elapsed Time = 152.7046 Seconds
Real Time = 152.7046 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
86.8 132.5 157.04 11400 0.0116 0.0138 HTML::Template::output
11.7 17.94 17.945 539401 0.0000 0.0000 HTML::Template::param
1.58 2.410 2.410 52900 0.0000 0.0000 HTML::Template::_globalize_vars
1.33 2.025 2.025 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
0.66 1.009 1.009 11300 0.0001 0.0001 HTML::Template::clear_params
0.49 0.742 152.31 1200 0.0006 0.1269 HTML::Template::LOOP::output
0.24 0.367 0.402 1 0.3667 0.4025 HTML::Template::_parse
0.11 0.168 0.168 4900 0.0000 0.0000 HTML::Template::URLESCAPE::escape
0.10 0.154 0.154 5800 0.0000 0.0000 HTML::Template::ESCAPE::escape
0.05 0.070 0.149 1 0.0699 0.1492 main::BEGIN
0.03 0.050 0.079 9 0.0055 0.0088 HTML::Template::BEGIN
0.01 0.020 0.020 1 0.0200 0.0200 HTML::Template::_init_template
0.01 0.020 0.020 3 0.0067 0.0066 vars::BEGIN
0.01 0.017 0.017 577 0.0000 0.0000 HTML::Template::VAR::new
0.01 0.010 0.010 2 0.0050 0.0050 DynaLoader::BEGIN
Total Elapsed Time = 152.7046 Seconds
Real Time = 152.7046 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
86.8 132.5 157.04 11400 0.0116 0.0138 HTML::Template::output
11.7 17.94 17.945 539401 0.0000 0.0000 HTML::Template::param
1.58 2.410 2.410 52900 0.0000 0.0000 HTML::Template::_globalize_vars
1.33 2.025 2.025 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
0.66 1.009 1.009 11300 0.0001 0.0001 HTML::Template::clear_params
0.49 0.742 152.31 1200 0.0006 0.1269 HTML::Template::LOOP::output
0.24 0.367 0.402 1 0.3667 0.4025 HTML::Template::_parse
0.11 0.168 0.168 4900 0.0000 0.0000 HTML::Template::URLESCAPE::escape
0.10 0.154 0.154 5800 0.0000 0.0000 HTML::Template::ESCAPE::escape
0.05 0.070 0.149 1 0.0699 0.1492 main::BEGIN
0.03 0.050 0.079 9 0.0055 0.0088 HTML::Template::BEGIN
0.01 0.020 0.020 1 0.0200 0.0200 HTML::Template::_init_template
0.01 0.020 0.020 3 0.0067 0.0066 vars::BEGIN
0.01 0.017 0.017 577 0.0000 0.0000 HTML::Template::VAR::new
0.01 0.010 0.010 2 0.0050 0.0050 DynaLoader::BEGIN
HTML::Template::Compile
-----------------------
C:\Test>perl -d:DProf bar.pl
-----------------------
C:\Test>perl -d:DProf bar.pl
C:\Test>dprofpp
Exporter::export has -6 unstacked calls in outer
Exporter::Heavy::heavy_export has 6 unstacked calls in outer
Total Elapsed Time = 36.19448 Seconds
User+System Time = 35.85548 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
43.6 15.65 27.876 11400 0.0014 0.0024 HTML::Template::Compile::_runtime_
start
36.5 13.12 13.121 403804 0.0000 0.0000 HTML::Template::param
7.93 2.845 38.938 100 0.0285 0.3894 HTML::Template::Compile::__ANON__
6.69 2.397 2.397 52900 0.0000 0.0000 HTML::Template::_globalize_vars
6.00 2.150 2.150 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
4.15 1.489 1.621 87300 0.0000 0.0000 HTML::Template::Compile::_runtime_
deref
2.97 1.065 1.065 11300 0.0001 0.0001 HTML::Template::clear_params
1.84 0.661 0.752 1 0.6610 0.7515 HTML::Template::Compile::_compile
1.05 0.377 0.392 1 0.3767 0.3925 HTML::Template::_parse
0.25 0.088 2.239 11400 0.0000 0.0002 HTML::Template::Compile::_runtime_
stop
0.24 0.085 0.091 43 0.0020 0.0021 HTML::Template::Compile::_generate
0.23 0.084 0.084 5800 0.0000 0.0000 HTML::Template::Compile::_runtime_
escape
0.22 0.079 0.078 101 0.0008 0.0008 HTML::Template::_find_file
0.17 0.060 0.248 8 0.0075 0.0310 HTML::Template::Compile::BEGIN
0.14 0.050 0.079 9 0.0055 0.0088 HTML::Template::BEGIN
Exporter::export has -6 unstacked calls in outer
Exporter::Heavy::heavy_export has 6 unstacked calls in outer
Total Elapsed Time = 36.19448 Seconds
User+System Time = 35.85548 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
43.6 15.65 27.876 11400 0.0014 0.0024 HTML::Template::Compile::_runtime_
start
36.5 13.12 13.121 403804 0.0000 0.0000 HTML::Template::param
7.93 2.845 38.938 100 0.0285 0.3894 HTML::Template::Compile::__ANON__
6.69 2.397 2.397 52900 0.0000 0.0000 HTML::Template::_globalize_vars
6.00 2.150 2.150 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
4.15 1.489 1.621 87300 0.0000 0.0000 HTML::Template::Compile::_runtime_
deref
2.97 1.065 1.065 11300 0.0001 0.0001 HTML::Template::clear_params
1.84 0.661 0.752 1 0.6610 0.7515 HTML::Template::Compile::_compile
1.05 0.377 0.392 1 0.3767 0.3925 HTML::Template::_parse
0.25 0.088 2.239 11400 0.0000 0.0002 HTML::Template::Compile::_runtime_
stop
0.24 0.085 0.091 43 0.0020 0.0021 HTML::Template::Compile::_generate
0.23 0.084 0.084 5800 0.0000 0.0000 HTML::Template::Compile::_runtime_
escape
0.22 0.079 0.078 101 0.0008 0.0008 HTML::Template::_find_file
0.17 0.060 0.248 8 0.0075 0.0310 HTML::Template::Compile::BEGIN
0.14 0.050 0.079 9 0.0055 0.0088 HTML::Template::BEGIN
C:\Test>dprofpp -r
Exporter::export has -6 unstacked calls in outer
Exporter::Heavy::heavy_export has 6 unstacked calls in outer
Total Elapsed Time = 36.14248 Seconds
Real Time = 36.14248 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
44.1 15.93 28.116 11400 0.0014 0.0025 HTML::Template::Compile::_runtime_
start
36.1 13.05 13.053 403804 0.0000 0.0000 HTML::Template::param
8.17 2.954 39.267 100 0.0295 0.3927 HTML::Template::Compile::__ANON__
6.69 2.419 2.419 52900 0.0000 0.0000 HTML::Template::_globalize_vars
5.97 2.158 2.158 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
4.02 1.453 1.605 87300 0.0000 0.0000 HTML::Template::Compile::_runtime_
deref
2.91 1.051 1.051 11300 0.0001 0.0001 HTML::Template::clear_params
1.83 0.661 0.752 1 0.6610 0.7515 HTML::Template::Compile::_compile
1.04 0.377 0.392 1 0.3767 0.3925 HTML::Template::_parse
0.26 0.094 0.094 5800 0.0000 0.0000 HTML::Template::Compile::_runtime_
escape
0.24 0.088 2.247 11400 0.0000 0.0002 HTML::Template::Compile::_runtime_
stop
0.24 0.085 0.091 43 0.0020 0.0021 HTML::Template::Compile::_generate
0.19 0.069 0.078 101 0.0007 0.0008 HTML::Template::_find_file
0.17 0.060 0.258 8 0.0075 0.0322 HTML::Template::Compile::BEGIN
0.16 0.058 0.058 4900 0.0000 0.0000 HTML::Template::Compile::_runtime_
urlescape
Exporter::export has -6 unstacked calls in outer
Exporter::Heavy::heavy_export has 6 unstacked calls in outer
Total Elapsed Time = 36.14248 Seconds
Real Time = 36.14248 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
44.1 15.93 28.116 11400 0.0014 0.0025 HTML::Template::Compile::_runtime_
start
36.1 13.05 13.053 403804 0.0000 0.0000 HTML::Template::param
8.17 2.954 39.267 100 0.0295 0.3927 HTML::Template::Compile::__ANON__
6.69 2.419 2.419 52900 0.0000 0.0000 HTML::Template::_globalize_vars
5.97 2.158 2.158 52900 0.0000 0.0000 HTML::Template::_unglobalize_vars
4.02 1.453 1.605 87300 0.0000 0.0000 HTML::Template::Compile::_runtime_
deref
2.91 1.051 1.051 11300 0.0001 0.0001 HTML::Template::clear_params
1.83 0.661 0.752 1 0.6610 0.7515 HTML::Template::Compile::_compile
1.04 0.377 0.392 1 0.3767 0.3925 HTML::Template::_parse
0.26 0.094 0.094 5800 0.0000 0.0000 HTML::Template::Compile::_runtime_
escape
0.24 0.088 2.247 11400 0.0000 0.0002 HTML::Template::Compile::_runtime_
stop
0.24 0.085 0.091 43 0.0020 0.0021 HTML::Template::Compile::_generate
0.19 0.069 0.078 101 0.0007 0.0008 HTML::Template::_find_file
0.17 0.060 0.258 8 0.0075 0.0322 HTML::Template::Compile::BEGIN
0.16 0.058 0.058 4900 0.0000 0.0000 HTML::Template::Compile::_runtime_
urlescape
I've been using this on my site for about a month now. It supports all of the features of H::T, and also includes the enhancements I've done locally. I would like to figure out a way to share it (if it's of interest) 'cause I'm sure the manner in which it's implemented could always be improved.
- Bob Diss
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!