[Petal] Re: Using Test::More

Jean-Michel Hiver jhiver at mkdoc.com
Wed Apr 9 18:49:45 BST 2003


> One thing that does give a speed advantage is using a string instead of an 
> array to store the built template. My code can switch between using a string 
> or an array and the difference is up to 30% improvement with strings, so it 
> might be worth doing that inside Petal's CodeGenerator.

What?

Doing something like $out .= 'something' is faster than doing push @out,
'something' and then joining everything? Is that what you're saying?


> The main difference is that I don't use the Petal hash, I just use an ordinary 
> hash. I parse all the expressions beforehand so compile time is longer but 
> then execution is speeded up a lot.

How do you know wether 'foo/bar' is $foo->{bar} or $foo->bar() ?


> My benchmark is processing a template from a Chinese dictionary program. 
> Before you improved the Hash code there was a massive speedup around 30-40 
> times but now it's only about 3 times faster.

Yes, I gained an order of magnitude of speed with last speed
improvements. There's nothing worse than too-early optimizations :-)


> I'll try just integrating the expression parsing (and forgetting about all my 
> other stuff). It should be possible to speed things up considerably.

Well, apparently using a string instead of an array seems good as well.


> > I think it should always fetch the local variable first. 'local' is 
> > misleading for us Perl freaks, I think we should be really read it as 'my'.
> 
> Sounds right to me, I'd like to find out what Zope does but I don't have it 
> installed.

I don't know... There used to be a couple of guys from the ZPT
subscribed on Petal mailing list... do you guys have an answer to that?


> > I think ;; is a mistake. There is a well known mechanism to escape meta 
> > characters which is used by almost everything out there which consists 
> > of backlashing them, which is why I consciously broke this TALES rule.
> > 
> > Why re-invent the wheel?
> 
> I defintely agree with you, ;; makes the parsing much trickier.

I'm not really worried about the parsing but I think that backslashing
is a proven working mechanism, that actually leaves a lot of room for
expansion.


> a/hash_key/5/get()

I don't think that the '()' part is TALES compliant, but I could be
wrong.


> If you know that $hash->{a} is a hashref and $hash->{a}->{hash_key} is an 
> array ref and $hash->{a}->{hash_key}->[5] is an object then it doesn't have 
> to think about types at runtime. When I rewrite my benchmark template to take 
> advantage of this, it almost doubles in speed again but it's a big break in 
> compatibilty with TALES.

Plus it looks really bad I think.

Anyway, thanks for your to-come improvements! I'm sure everybody on the
list appreciates that.

Cheers,
-- 
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
jhiver at mkdoc.com  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


More information about the Petal mailing list