On Mon, Mar 7, 2011 at 6:22 AM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote: > On Sat, Mar 5, 2011 at 12:41, Peter Rabbitson <rabbit-p5p@rabbit.us> wrote: > Moose rarely (unless you use certain MooseX::* modules) incurs > "runtime" type checking. It does type checking at object > *construction* time, but that type checking is usually fast enough for > any program you care to write. Here's a benchmark to back that up: > > https://gist.github.com/858378 > > As you can see Moose is able to construct 180k objects per second > v.s. around 350k objects for a similar pure-Perl class. However if you > don't inline the object constructor Moose does 14k/s. > > But for *accessing* the data Moose was actually faster than my first > stab at writing an accessor, meaning that in most code normal > programmers write Moose would speed up your code at the expense of > slightly more memory use. This is also what the Catalyst folks found > IIRC when they switched to Moose, I suggest you read up on that. To be fair, core Moose does in fact type check on accessor access. Now as a community we generally recommend immutable objects with read only accessors. Additionally type checks are only performed if you *tell* Moose the Type you want to check (via the isa param to "has"). So your argument that it "rarely" happens may in fact be the case. Additionally your benchmark of the Moose vs Perly examples above isn't entirely fair. Your Moose classes are 'ro' while your Perly class has full accessor logic. That said Moose will perform a check to make sure you didn't try passing a param to a read-only accessor so I think it evens out in the end. I only mention these things because we've traditionally tried to encourage a policy of being open and forthright about Moose's performance. >> in my line of work it in fact *never* is > > I don't know what kind of work you do, but I very much doubt that > you're unable to spare 5-10MB extra ram for Mouse or Moose. > > Particularly since Moose is not an all-or-nothing thing. I've written > programs where 95% of the program used boilerplate Moose code but in > one specific hot code path I wrote a pure-Perl class instead. I'm curious about this too since we recently benchmarked Moose and found it was fast enough to drive the Firmata protocol to talk to Arduinos which work at the hundreds-of-objects-per-second rate. I've worked in the Finance arena too (and in fields that were similar levels of data intensity) and found Moose to perform adequately there too for 90% of the use caes *I* ran into. These were far outside of the web-dev echo chamber. -ChrisThread Previous | Thread Next