Hello, all.

What I would like to do is optimize access to template variables, basically
for data extractions. (The templates provide the presentation for rows of
data dynamically SELECTed by a program using dbi.)

The rows can come out in any order (the template actually defines which
fields are selected from the database for efficiency, ... No need to join
tables if the template doesn't require them!

To make the template more meaningful, I'm using fetchrow_hashref() in DBI to
provide template variables that are easy for template writers to write;

This works quite well, but for large queries, the program spends most of its
time in Template::Stash::XS::get() (about 36% percent of its time, according
to dprofpp) ... Also, the overhead of using a hash for each row of data gets
impeding with large rowcounts.

So, what I'm thinking about doing is creating something that will allow me
to supply a "map" that will allow template writer's to still use [%
data.field_a %] [% data.fieldb %] etc, but will use the map to map field_a
into it's column-ordered position in an array; This way I can use
fetchrow_arrayref() instead of fetchrow_hashref() (for the sake of
memory/speed efficiency).  This would sort of be a Stash equivalent of a
Perl pseudo-hash, although I haven't actually used one of those myself. I
know I can do this because I know the name+order of all the fields coming
from the dbi query.  But I don't want to just move the hash key lookup from
one part of the program to another...

I'm writing to the list to see if someone else has run into this situation
and/or figured out a better way to handle it.


BTW:
I'm not letting templates use DBI themselves, the templates just provide the
presentation for the rows, and the actual program engine decides how to best
perform the query... It just provides the data as hashes right now.

The best way would probably be having the template re-write itself when it
gets parsed.  It could turn all of my templates [% data.field_c %] into [%
data.4 %] "behind the scenes" while it is being parsed.  This could probably
be done by sub-classing the Template::Parser object....

I would like to say something like this when I'm all done:

%Template::Parser::field_map = (  field_a => 0,
  field_b => 1,
  field_c => 4
  );   ## etc.


and have it simply rewrite all of the "data" hash accesses to be array
accesses instead...

What do you all think?

-Bryan Shannon




Reply via email to