in reply to Re^4: POE OO sessions - accessing overwritten methods
in thread POE OO sessions - accessing overwritten methods

Interesting. But they are quite wrong (see above). They start out with a factual truth: passing in by @_ is fastest. (I wonder if passing in a single array ref would be faster ... one way to find out!) However, they then go and explain how they'll use this "fast" method to go and make it readable and extendable. Well, guess what. It's not.

Rather than starting out with the fastest method and making it more readable, they should have evaluated all methods, and picked the most readable and fast method. They discarded all alternatives over a perceived speed difference, and then used up way more than that speed difference in making it readable. Kudos for making it readable and forward-thinking. A pox for thinking inside an artificial box.

Update: Yes, a major typo in the code screwed this up. Ok, so it's not significantly slower. I still think it's unreadable :-)

#! /usr/bin/perl use Benchmark qw(cmpthese); use constant {OBJECT => 0, KERNEL => 1, HEAP => 2, SESSION => 3, }; cmpthese( 0, { POE => sub { poe_style(qw(a b c d)); }, Normal => sub { regular_style(qw(a b c d)); }, Ref_Copy => sub { reg_ref('a', [qw(b c d)]); }, Ref_Named => sub { ref_named('a', { kernel => 'b', heap => 'c', session => 'd', } ); }, Named => sub { named_style('a', kernel => 'b', heap => 'c', session => 'd', ); }, Shift => sub { shift_style(qw(a b c d)); }, } ); sub poe_style { my ($self, $kernel, $heap, $session) = @_[ OBJECT, KERNEL, HEAP, S +ESSION ]; 0; } sub regular_style { my $self = shift; my ($kernel, $heap, $session) = @_; 0; } sub reg_ref { my $self = shift; my ($kernel, $heap, $session) = @$_[0]; 0; } sub named_style { my $self = shift; my %opts = @_; 0; } sub ref_named { my $self = shift; my $opts = $_[0]; 0; } sub shift_style { my $self = shift; my $kernel = shift; my $heap = shift; my $session = shift; 0; }

Short version: The calling types they said would be slower than "normal" are. But they're all faster than the one they ended up with. The unintuitiveness of this style still causes problems. As in calling SUPER.

Replies are listed 'Best First'.
Re^6: POE OO sessions - accessing overwritten methods
by BrowserUk (Patriarch) on Feb 12, 2005 at 18:53 UTC
    Interesting. But they are quite wrong (see above).

    Actually, you're quite wrong. And if you learnt to use strict you'd have seen your mistake.

    Here are the results of your benchmark once your mistake is corrected.

    [18:46:32.42] P:\test>junk Rate Ref_Named Named Ref_Copy Shift POE + Normal Ref_Named 119185/s -- -3% -35% -81% -83% + -84% Named 122333/s 3% -- -34% -81% -83% + -84% Ref_Copy 183991/s 54% 50% -- -71% -74% + -76% Shift 639848/s 437% 423% 248% -- -9% + -17% POE 701269/s 488% 473% 281% 10% -- + -9% Normal 768699/s 545% 528% 318% 20% 10% + --
    And that should absolutely zero surprise to anyone: OBJECT, KERNEL, HEAP, and SESSION are all subs which would mean subroutine calls.

    You're the one in for the surprise. They aren't subroutine calls, they are constant subroutine calls. What difference does that make?

    It means that at compile time, Perl can detect that they are constant subroutines.

    [18:43:58.10] P:\test>perl -MO=Deparse -e"use constant{ONE=>1,TWO=>2}; + for( ONE .. TWO) { print }" use constant ({'ONE', 1, 'TWO', 2}); foreach $_ (1 .. 2) { print $_; } -e syntax OK

    Did you spot your error yet? use strict would have told you way back up ^ there somewhere--but I guess that is another "artificial box" you'd rather stay out of.

    So, what do you think we should put a pox on now? Flying by the seat of your pants! :)


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

      I swear - I type

      #!/usr/bin/perl -w use strict;
      as second nature. But this time, doing a benchmark, I got confused... and forgot to add it back in. I guess I'm doing K.P. duty for the monastary this week...