[Melbourne-pm] New module: Number::Phone::AU

Toby Wintermute tjc at wintrmute.net
Thu Jan 6 21:52:17 PST 2011

On 7 January 2011 16:01, Michael G Schwern <schwern at pobox.com> wrote:
> On 2011.1.7 2:45 PM, Toby Wintermute wrote:
>> I use Moose everywhere, but don't want some random modules using Mouse instead.
> I want to answer that in detail, because Mouse gets a lot of crap based on
> outdated information.  I've been relying on Mouse extensively for
> Test::Builder2 and it continues to amaze me how complete and fast it is.

I tried search-and-replacing all "use Moose" to "use Mouse" in one of
my apps to try a comparison of total memory use in a large project,
however with Mouse the project fails to fire up at all -- and I don't
think I'm using Moose's features extensively.

> 1) Mouse might be less feature complete.
> You'd be hard pressed to find a feature which is missing from Mouse at this
> point.  And obviously Mouse has all the features needed for Number::Phone::AU.

As above, it failed immediately; it looks like I need to mess around
with some extra modules before Mouse supports attribute traits.

> 2) Moose + Mouse consumes more memory then just Moose.
> I measure it at about 1.5 megs more memory or just 10% of Moose.  Insignificant.

But equally, does it matter if you just used Moose on its own? You
would use less memory than both, and Moose's memory use, in a large
project, is unlikely to be significant.

> There's no really compelling reason why some random module, which is a black
> box, can't use Mouse.

I just dislike having multiple implementations of the same protocol
loaded; it seems messy to me.

>> How about using Any::Moose, which will use Mouse unless Moose is loaded?
> Short version: sure, there's probably no harm.
> Long version:
> The problem with Any::Moose is now you may get different bugs depending on if
> Moose or Mouse is loaded.  Used to be a bigger problem than it is now.
> The second problem with Any::Moose is that Mouse is now significantly *faster*
> at runtime than Moose.  This is likely the result of Mouse::XS.  Here's my
> benchmarks adapting Ovid's from
> http://blogs.perl.org/users/ovid/2010/01/roles-without-moose.html

Mmm... so why couldn't the effort to speed up Mouse be put into Moose too?

>From Ovid's blog, he notes:
"Mouse seemed promising, but initial benchmarks with the above code
showed it's getters/setters running slightly slower than Moose
getter/setters! We can take a performance hit on load, but on runtime,
we have to be careful."
(That was a year ago, and I guess Mouse sped up since then.)
But - sooner or later Moose will get the same treatment.

(Aside: I am a little wary of the high-performance XS stuff that comes
along; sure, they are fast, but things like Template::Stash::XS,
Template::Alloy::XS and Class::XSAccessor have left a bad taste in my
mouth with their bugs.)

> Using Mouse is *faster* than a simple Perl accessor.  It's approaching raw
> hash access.  Moose with a type check is 10x slower than raw hash access.
> So if you want performance, use Mouse use Moose.  This runs directly counter
> to Any::Moose.

Aren't we prematurely optimising here though?
You're taking a module that has less features and less of a track
record and is probably less stable, and choosing it because it's
currently faster for stuff.. when that stuff might not actually be
significant to your programs' performance at all.
(Although OK, if its your accessors, it's quite likely it would help)

> Mind you, I'm sure you can kill Mouse performance pretty easily, but as it's a
> module tailor built to produce the Moose interface (rather than a sugar
> wrapper around a generic Meta Object Protocol) I expect it to continue to get
> faster.
> Moose is about the MOP, and flexibility for MooseX and design purity.  Mouse
> is just implementing Moose and can optimize like mad.  Both are valid goals.
> Both can happily live together in the same project.  Pick which one you need
> for your code.

Well, it does sound like Mouse is in a better state than I thought; I
thought it had died off a bit once Moose had sped up a bit.
Perhaps I can look into it and see if it makes a difference to
projects I care about.


Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

More information about the Melbourne-pm mailing list