Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^14: The Most Essential Perl Development Tools Today (negative)

by BrowserUk (Patriarch)
on Jan 13, 2013 at 18:44 UTC ( [id://1013119]=note: print w/replies, xml ) Need Help??


in reply to Re^13: The Most Essential Perl Development Tools Today (negative)
in thread The Most Essential Perl Development Tools Today

then the subroutine probably has almost no code in it at all, and the solution is to inline the tiny amount of code in the subroutine and remove the calling overhead entirely.

Sure, you could do that, but are you really going to allow all the callers of your objects to access their attributes directly rather than going through getters?

Little bits add up! Here a 25% penalty just to satisfy two pointless P::C rules:

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $o = bless { X=>1 }, 'main'; sub getX1{ my $self = shift; return $self->{X}; } sub getX2{ return $_[0]->{X}; } sub getX3{ $_[0]->{X}; } cmpthese -1, { A=> q[ my $x = $o->getX1(); ], B=> q[ my $x = $o->getX2(); ], C=> q[ my $x = $o->getX3(); ], }; __END__ C:\test>junk19 Rate A B C A 1441709/s -- -11% -20% B 1611352/s 12% -- -10% C 1797147/s 25% 12% --

And that is just one level deep. Imagine (or test) the affect of calling a method that itself needs to call 2 or 3 getter() from one of its sub objects.

The penalties, for what are purely cosmetic affectations, add up.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

Replies are listed 'Best First'.
Re^15: The Most Essential Perl Development Tools Today (negative)
by tobyink (Canon) on Jan 13, 2013 at 20:03 UTC
    #! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $o = bless { X=>1 }, 'main'; sub getX1{ my $self = shift; return $self->{X}; } sub getX2{ return $_[0]->{X}; } sub getX3{ $_[0]->{X}; } use Class::XSAccessor getters => { getX4 => 'X' }; cmpthese -1, { A=> q[ my $x = $o->getX1(); ], B=> q[ my $x = $o->getX2(); ], C=> q[ my $x = $o->getX3(); ], D=> q[ my $x = $o->getX4(); ], }; __END__ Rate A B C D A 251509/s -- -6% -12% -64% B 267957/s 7% -- -7% -62% C 286968/s 14% 7% -- -59% D 707950/s 181% 164% 147% --
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Ignore that. I typoed (again) and fooled my self.

      Class::XSAccessor is very impressive. I'd like to see a version that worked with blessed arrays.

      But the primary point still stands. Getters are only one of many types of sub/method call that don't do very much, but you would not want to have to manually inline them everywhere they are used.

        Class::XSAccessor is freakishly fast. Given that a sub call still has to happen, you wouldn't expect it to eliminate that much overhead.

        It does do one slightly scary thing though...

        #! perl -slw use strict; use Data::Dumper; sub get_pp { $_[0]->{X}; } use Class::XSAccessor getters => { get_xs => 'X' }; { my $o = bless { X=>1 }, 'main'; my $ref = \($o->get_pp); $$ref++; print Dumper($o); } { my $o = bless { X=>1 }, 'main'; my $ref = \($o->get_xs); $$ref++; print Dumper($o); }

        This came up in a recent Moose-related thread.

        PS: there is Class::XSAccessor::Array as part of the same distribution.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^15: The Most Essential Perl Development Tools Today (negative)
by Anonymous Monk on Jan 14, 2013 at 09:37 UTC
    I could be jumping to the wrong conclusion here, but you mentioned this speed boost before. Would this improve speed of web apps, using CGI::Application?

      Any performance gain is a nice side effect. The primary point is, not doing that which is not necessary, solely to satisfy some twisted notion of "correctness".

      Would this improve speed of web apps, using CGI::Application?

      Probably. Whether it would be enough that your clients would notice is doubtful, but if you are running the application on a server farm, you might be able to measure a reduction in your power usage that would be worth having.

      I can imagine that if Google found a way to reduce their electricity bill by even 5% by doing something -- or rather not doing something -- that required no other effort and had no other cost, they'd be all over it.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.
        I will look into this. But CGI::Application seems hevily dependant on use of $self-> and returning from each runmode. http://search.cpan.org/~markstos/CGI-Application-4.50/lib/CGI/Application.pm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1013119]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-19 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found