Re: Getting data from template?
Mathew Robertson <[email protected]> Fri, 30 Jan 2009 08:55:39 +1100
| Newsgroups | gmane.comp.lang.perl.modules.html-template |
|---|---|
| Organization | Nielsen//NetRatings |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============0914103157654560385==
Content-Type: multipart/alternative;
boundary="------------050005050704080902000002"
This is a multi-part message in MIME format.
--------------050005050704080902000002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
>> Is there a version that works with HTML::Template::Pro? I'm using a
>> template system that loads HTML::Template::Pro if available (for the
>> speed enhancements)
>>
>
> Really? Did you do benchmarks and find that your templating was bottleneck? And if so, how much of a
> gain did you get from HTML::Template::Pro? If page takes 1 sec to create on the server and your
> templating takes only 10% of your execution time (and I've never had a real page where that was the
> case, it's usually closer to 2-5%) and you increase the speed of your templating by 25x (that's the
> max claimed by H::T::P) then you've taken a full 0.096 sec off.
>
> That little gain is just not worth it to me if you have to jump through hoops to make other things
> with with the module (like you're trying to do with H::T::Sec). Plus it doesn't support query()
> which I find extremely handy.
>
I did some performance profiling of H::T some time ago -> it turns out
that there is quite a bit of speed up (somewhere between 10% and 10x,
depending on the page) by re-writing part of the code located around
line 2660.
hope this helps,
Mathew
patch -> replace the options{associate} conditional with this:
# support the associate magic, searching for undefined params and
# attempting to fill them from the associated objects.
if (scalar(@{$options->{associate}})) {
my @undef_params;
foreach my $param (keys %{$self->{param_map}}) {
next if (defined $self->param($param));
push @undef_params, $param;
}
if (scalar(@undef_params)) {
my $value;
# if case sensitive mode or no CGI objects, we can use the fast path
if ($options->{case_sensitive} or (grep { !/^1/ } map {
UNIVERSAL::isa($_,'HTML::Template') } @{$options->{associate}}) == 0) {
foreach my $param (@undef_params) {
foreach my $associated_object (reverse @{$options->{associate}}) {
$value = $associated_object->param($param);
next unless (defined $value);
$self->param($param, scalar $value);
last;
}
}
} else {
my %case_map;
foreach my $associated_object (@{$options->{associate}}) {
map { $case_map{$associated_object}{lc($_)} = $_ }
$associated_object->param();
}
my $associated_param;
foreach my $param (@undef_params) {
foreach my $associated_object (reverse @{$options->{associate}}) {
$associated_param = $case_map{$associated_object}{$param};
next unless (defined $associated_param);
$value = $associated_object->param($associated_param);
next unless (defined $value);
$self->param($param, scalar $value);
last;
}
}
}
}
}
--------------050005050704080902000002
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote cite="mid:[email protected]" type="cite">
<blockquote type="cite">
<pre wrap="">Is there a version that works with HTML::Template::Pro? I'm using a
template system that loads HTML::Template::Pro if available (for the
speed enhancements)
</pre>
</blockquote>
<pre wrap=""><!---->
Really? Did you do benchmarks and find that your templating was bottleneck? And if so, how much of a
gain did you get from HTML::Template::Pro? If page takes 1 sec to create on the server and your
templating takes only 10% of your execution time (and I've never had a real page where that was the
case, it's usually closer to 2-5%) and you increase the speed of your templating by 25x (that's the
max claimed by H::T::P) then you've taken a full 0.096 sec off.
That little gain is just not worth it to me if you have to jump through hoops to make other things
with with the module (like you're trying to do with H::T::Sec). Plus it doesn't support query()
which I find extremely handy.
</pre>
</blockquote>
I did some performance profiling of H::T some time ago -> it turns
out that there is quite a bit of speed up (somewhere between 10% and
10x, depending on the page) by re-writing part of the code located
around line 2660.<br>
<br>
hope this helps,<br>
Mathew<br>
<br>
patch -> replace the options{associate} conditional with this:<br>
<br>
# support the associate magic, searching for undefined params and<br>
# attempting to fill them from the associated objects.<br>
if (scalar(@{$options->{associate}})) {<br>
my @undef_params;<br>
foreach my $param (keys %{$self->{param_map}}) {<br>
next if (defined $self->param($param));<br>
push @undef_params, $param;<br>
}<br>
if (scalar(@undef_params)) {<br>
my $value;<br>
# if case sensitive mode or no CGI objects, we can use the fast
path<br>
if ($options->{case_sensitive} or (grep { !/^1/ } map {
UNIVERSAL::isa($_,'HTML::Template') } @{$options->{associate}}) ==
0) {<br>
foreach my $param (@undef_params) {<br>
foreach my $associated_object (reverse
@{$options->{associate}}) {<br>
$value = $associated_object->param($param);<br>
next unless (defined $value);<br>
$self->param($param, scalar $value);<br>
last;<br>
}<br>
}<br>
} else {<br>
my %case_map;<br>
foreach my $associated_object (@{$options->{associate}}) {<br>
map { $case_map{$associated_object}{lc($_)} = $_ }
$associated_object->param();<br>
}<br>
my $associated_param;<br>
foreach my $param (@undef_params) {<br>
foreach my $associated_object (reverse
@{$options->{associate}}) {<br>
$associated_param = $case_map{$associated_object}{$param};<br>
next unless (defined $associated_param);<br>
$value = $associated_object->param($associated_param);<br>
next unless (defined $value);<br>
$self->param($param, scalar $value);<br>
last;<br>
}<br>
}<br>
}<br>
}<br>
}<br>
<br>
</body>
</html>
--------------050005050704080902000002--
--===============0914103157654560385==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
--===============0914103157654560385==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Html-template-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/html-template-users
--===============0914103157654560385==--