Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Moose is Perl: A Guide to the New Revolution (manxome.org)
10 points by Mithaldu on July 26, 2011 | hide | past | favorite | 7 comments


Moose is cool, but it can be a significant performance impediment to any program that uses Moose-wrapped objects or their methods frequently (this is true even of the XS-based Moose implementation). Function calls are expensive in Perl, and adding Moose wrappers causes them to be invoked sometimes an order of magnitude more frequently. You can see how bad it is by profiling your code with NYTProf.

Consequently, I've often recommended implementors extricate Moose from performance-critical programs.


Very odd, because for regular methods, Moose does not wrap anything.

There is a compile time penalty for Moose overall, but for instance, the Moose generated accessors typically benchmark very well in comparison. They will start to slow down when you add type constraints, but this is essentially extra code you are asking Moose to execute so you can't expect to get it for free.

I highly suspect you have been using MooseX::Declare or MooseX::Method::Signatures, both of which have a high performance penalty for method calls. These modules should not be looked at as being Moose, they are optional extensions.


Much of the overhead can be attributed to Moose::Util::TypeConstraints, which is part of the base package.


Yes, but this is an optional part of the base package and one of the places in Moose where you pay for how much you use it. In the end, you can simply comment out the type check if it is causing performance issues.

I would be interested to know what version of Moose you used when you made this judgement? Because, the recent 2.0200 version includes inlined type constraints, which provided a non-trivial boost in performance for the native types as well as custom types (provided you include an inlined version in your custom type). If you were profile your code again, you might find a sizable change (and if not, please feel free to send the profile output to the Moose mailing list for us to review).


I'm summarizing explanations from the #moose irc channel now:

Yes, type checks are the main source for performance issue.

However, they are completely optional. This means you can safely disable them in places where you think you don't need them, and only enable them where you think you do. Keep in mind that writing something manually though won't be faster.

This means, that when performance is an issue, your first step would be to fork your dependency and disable type checks. That should get you almost the same speed as a complete Moose-free rewrite, at a fraction of the cost of an actual rewrite. If that really isn't enough, you're likely to get better performance by rewriting in C, than in Moose-free Perl.


Good feedback. Thanks!


Give some numbers when you make such statements. Just what kind of performance gains (comparing gain to overall runtime) did you get? And what Moose version was used?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: