[Petal] [PATCH] refactored Petal::Hash::Var + misc

Steve Purkis spurkis at mkdoc.com
Thu Jun 5 13:03:29 BST 2003


Hi all,

Attached is an updated patch for Petal::Hash::Var with a few bug fixes 
and some more updates:

    * error when trying to set nested variables (as discussed)
    * ability to turn off errors on undef variables with:
		$Petal::Hash::Var::ERROR_ON_UNDEF_VAR = 0;
    * benchmark tests in t/099_Benchmark.t

I've run the benchmarks against the current version of Petal and my 
patched version with the following results:

         	Templates Processed /s
Machine:	400MHz PPC	1.7 GHz x86
Current:	69.52/s   	315.62/s
Patched:	42.65/s   	206.39/s

Which indicates a drop of roughly 33% in performance.  Profiling it [1] 
shows that the Petal::Hash::Var::* methods are indeed where most of 
this hit comes from, though Cwd::_backtick_pwd() is #1 for both.

The benchmarks have memory caching turned on, and test processing a 
basic file, benchmark.html.  Feel free to improve the tests...

I personally see this drop in performance as negligible - processing 
200+ templates a second is more than enough to meet my needs [2], and I 
believe the benefits of well-factored code out weigh the loss.  If 
others see this as a problem, I'd suggest optimizing the patched 
version rather than disregarding the patch.

[1] running perl -d:DProf sometimes dumps core for the current version?
[2] but then 10 a second would do the trick for me ATM

Regards,
-Steve

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Petal-0.92-var-misc.patch
Type: application/octet-stream
Size: 27294 bytes
Desc: not available
Url : http://www.email-lists.org/pipermail/petal/attachments/20030605/16c4372c/Petal-0.92-var-misc.obj
-------------- next part --------------



On Wednesday, May 28, 2003, at 11:54  am, Steve Purkis wrote:

> Hi,
>
> I've done a major refactoring of Petal::Hash::Var with the following 
> goals in mind:
>
>     *	extensibility
>     *	readability
>     *	improved error reporting
>
> The patch introduces a parser object to Petal::Hash::Var.  IMHO, this 
> would do better off as something like Petal::Expression::Parser - then 
> other objects would be able to use it (which is what I was originally 
> planning on doing to auto-vivify things in Petal::Hash).
>
> Note that performance may drop slightly as a result of this patch: 
> what used to be one static method has now become many different 
> instance methods.  I doubt this will be a big issue though.
>
> Other things this patch addresses:
>
>     *	Fixes a bug: $current->$next methods always called with @args
>     *	regexs are now pre-compiled (though I think I've missed a couple)
>     *	TODO tests for auto-vivifying hashes (should these be errors 
> instead?)
>
> Regards,
> -Steve


More information about the Petal mailing list