On Thu, Jun 08, 2000 at 01:48:40PM +0100, Matt Sergeant wrote:
> On Thu, 8 Jun 2000, Greg Cope wrote:
> 
> > This may be veering off topic - but its been on my mind for a while now ....
> > 
> > Apart from thanking Stas for his benchmark work, which I find very
> > interesting (does he sleep ;-) - this and few few others (benchmarks) have
> > all touched on the area of including mod_perl output within HTML.  I have
> > always wonder what everyone else is doing on this front.
> > 
> > I usually suck a template into memory (one long line) - usually done at
> > startup.  I then create all the conent with either pushing onto an array, or
> > .= string concatination.  Finally I regex the template - looking for my tags
> > and replave those with output.  Needless to say that one page can onsists of
> > many templates (page or inside of table (bits from <tr> </tr>) etc ...).
> > 
> > From Stas previous benchmarks I've preloaded the mysql driver and now
> > usually use the "push" onto array to prepare content - Thanks Stas.
> > 
> > Who does everyone else do it ? Can this type of operation (that everyone
> > must do at some time) be optimised as aggressively as some of the others ?
> > Yet still keep the abstraction between design and content.
> 
> As far as I've seen, the fastest template systems are the ones that
> convert the template to Perl code. So that's what I do. The templates all
> call a method (in my case $Response->Write()) which appends to a
> string. If there are no exceptions (see the guide) the string is sent to
> the browser. If there are exceptions, I parse/send an error template with
> the error in the template.

I'm curious Matt, as opposed to what?, reparsing the template each
run?  Clearly reparsing would be a big loser in terms of performance.

But what other technique could be used..., hrm.., without direct
control over the pipe, I really don't think it would get too much
better than this.  I mean, you could yank out sections and stuff it
into an array that would be like: text, coderef, coderef, text, etc.
Like in an ASP template you would parse the file, grab sections
between <% %> and eval it as a code ref, and stuff it into your array.
But this would probably not work specifically in ASP's case, but you
might be able to pull it off in Embperl.  (Unless the array itself
could also point to arrays, etc.)  Overall..., I think compiling it
directly makes a lot more sense in 99.999% of template languages...,
otherwise you'd end up putting too many restrictions on the template
language itself.

Hmm..., sort of an interesting question, what ways could be utilized
in order to maximize speed in template execution.  I thought about
this a while ago, but after the fact I have to agree with Matt...,
just evaling each template as a package, or a code ref would be a
lot quicker, and if you could cook up another scheme, the resulting
code complexity might not pan out to be worth it.

> Of course I don't know if its the fastest possible method - I prefer to
> code cleanly first and worry about performance later. Much later. Clean
> code tends to lend itself to better performance in the long run anyway,
> because it's easier to optimise serious performance problems away.

Can't really disagree with that.  Clean code is 100x easier to work on
later.

Shane.

Reply via email to