in reply to Re^3: Some thoughts on Moose Attributes
in thread Some thoughts on Moose Attributes

I guess using internal accessors would (in Perl) facilitate changing the blessed reference type from hashref to arrayref. Or possibly vice versa, though a reason for doing the latter doesn't instantly spring to mind. But the main reason for switching from a hashref to an arrayref is performance. Array lookups using constant subs is a tad quicker than hash lookups.
I recall in the earlier days of Perl 5 there was an array-based mechanism added that pre-compiled the slot names into indexes. That was indeed faster, but it was deprecated and removed due to some issues I've forgotten.

There may be more experiments later, with Perl-6 lust and current work in moving parts of Moose to XS. Abstraction opens up all possibilities.

  • Comment on Re^4: Some thoughts on Moose Attributes

Replies are listed 'Best First'.
Re^5: Some thoughts on Moose Attributes
by BrowserUk (Patriarch) on May 02, 2011 at 02:21 UTC

    The simple fact is, looking up the address of a method, even with catching--without yet invooking it--is no faster than a hash lookup. That's because it *is* as hash lookup.

    And then you have to invoke it. And then it has to refernce the attribute through some mechanism. And then it has to return it.

    So, you have 'a hash lookup' versus 'a hash lookup, plus invocation, plus whatever mechanism to obtain the attribute value, plus the return'.

    It doesn't matter what happens inside the accessor to obtain the value, you've already lost by the time you looked up the address of the method. From that point on it is all down hill.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.