Is the performance hit with using MooseX::Declare mainly encountered during startup?
Is the performance hit with using MooseX::Declare mainly encountered whi开发者_如何学编程le 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?
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.
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.
精彩评论