How can we make this Moose faster?

(I make no apologies for the ChatGPT images in my recent blog posts, by the way. No artists are missing out on being paid: I wasn’t going to hire an artist to illustrate these blog posts which will be read by like three people.)

A while back, I wrote MooseX::XSAccessor which you can add to Moose classes to inspect your attributes and try to replace the accessors with faster XS-based ones. Now I’ve done the same for constructors (new) and destructors (DESTROY) with MooseX::XSConstructor.

There are probably still bugs, but initial benchmarks look promising:

            Rate Standard       XS
Standard  6392/s       --     -43%
XS       11228/s      76%       --

They’re mostly just a matter of importing the modules and forgetting about them. If the modules detect that your class is too complex for the XS modules to handle, they’ll sit back and let the regular Moose code work its magic. Give them a try. Let me know if they break things. They usually won’t.

Leave a comment

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.