tags:

views:

105

answers:

2

Is the performance hit with using MooseX::Declare mainly encountered while it does its initial magic (i.e. "translating" the definition into standard Perl syntax)? i.e. once the compile and initial runtime setup is complete, is there a performance difference in calling a MooseX::Declare method vs a method defined via traditional declaration?

+7  A: 

The answer is yes and no. Since MooseX::Declare uses MooseX::Method::Signatures to do parameter unpacking and validation, there is a runtime overhead compared to not validating parameters at all.

But if your idea of "traditional declaration" includes validating the number and type of your parameters (and it should if you want robust code) then there's no reason to think that the validation MXD/MXMS does would be any slower than the validation you would do yourself.

hobbs
Thanks for you reply. I typically do some validation of parameters, but not to the nth degree - I guess I take the Perlish approach of many other Perl developers. I guess what I like about MooseX::Declare is that the syntax promotes readability as much as anything else.
Dan Horne
+2  A: 

MooseX::Declare is a compile time conversion of declarative syntax to "true" Perl code. All of its overhead is at compile time.

The runtime overhead you speak of would be Moose type validation and coercion. Both of these are optional: you do not need to specify a type qualifier, and you do not need to specify is coerce. If you use neither, your runtime performance should be very close to what it would be without MooseX::Declare's magic.

So in runtime terms, it's win/win. You only pay for the features you use. Type validation is something you would have to do manually anyway, and coercion, while definitely a performance hit, is enabled on a per-argument basis.

rjh