|more useful options|
Slowdown when using Moose::Util::TypeConstraints with Regexp::Commonby kevbot (Chaplain)
|on Sep 02, 2008 at 05:16 UTC||Need Help??|
kevbot has asked for the
wisdom of the Perl Monks concerning the following question:
This is my first post to the monastery, so please take it easy on me :) I use Perl mostly as a hobby, and I have been slowly learning by reading various books and lurking around here. So, I think I finally have a question worth asking (most of the time a Super Search reveals that my question has already been answered). I have started to use Moose for anything object oriented and have found it to be very nice.
I recently wrote an application that creates a few thousand Moose objects. It seemed to run a bit slow so, I used Devel::DProf to help locate the bottleneck in my code. I was convinced that one of my methods would be involved. To my surprise, it seemed to be the combination of using Moose::Util::TypeConstraints with Regexp::Common
I have tried to reduce this down to a simple case based on the example given in Moose::Cookbook::Basics::Recipe4.
If I create the subtype using the technique in the recipe:
it seems to run slower than if I create the subtype like this:
The code that I use for benchmarking and profiling the difference between these two techniques is behind the readmore tags.
Comparing A and B:
I'm using the following:
I made a couple simple programs to create 10,000 objects using either technique. Then I used Devel::DProf to profile the code. The two highest values of 'ExclSec' for the creation of 10,000 AddressA objects were from these methods:
and for AddressB objects none of the Regexp::Common methods show up and these two methods have the highest values of 'ExclSec'.
I don't want to focus too much on the DProf results, since dprofpp is giving me negative elapsed time values and some negative 'CumulS' values. I have no idea why.
I just tried this out on Mac OS X with perl 5.8.8 (macports) and the results of the comparison are (same Moose and Regexp::Common versions)
So, it's not as noticeable on Mac OS X. I'm not sure why this differs so much from strawberry perl.
My question has a few parts: