Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

RE: autoload and selfload

by perlmonkey (Hermit)
on Jul 11, 2000 at 08:43 UTC ( [id://21917]=note: print w/replies, xml ) Need Help??


in reply to autoload and selfload

There can be a significant perfomance penalty for using AUTOLOAD on OOP get/set functions however. It really depends on the objects purpose. We had some get/set routines autoloaded for database objects. So a autoloaded get/set function would get called for each record of each row that got returned, and it sucked majorly. By removing the autoloading and just accessing the data structure directly we increased the peformance by over 20 times (over a minute to about 3 seconds).

But AUTOLOADING is great for objects where the get/setting is not a significant process. And I love it for those lazy days of hacking out proof-of-concept stuff in the OOP world.

Replies are listed 'Best First'.
RE: RE: autoload and selfload
by davorg (Chancellor) on Jul 11, 2000 at 12:24 UTC

    This is generally true, but there is an example in Conway's book where he uses AUTOLOAD for accessor methods, but creates a new method on the fly, so that AUTOLOAD is only called the first time that a particular method is used.

    The code looks like this (note use of no strict to allow symbolic references in a strictly (no pun intended) controlled manner.)

    Should probably point out that this isn't actually Damien Conway's code, but a slightly changed version that I hacked up.

    sub AUTOLOAD { no strict 'refs'; my ($self, $val) = @_; my ($name) = $AUTOLOAD =~ m/.*::(\w*)/; *{$AUTOLOAD} = sub { return @_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; return defined $val ? $self->{$name} = $val : $self->{$name}; }
    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      Cool, this is a very good idea for accessors. Thanks davorg (and Damien). I think I will start tweaking the code we have here to match.

      But for our problem mentioned before (the DB result objects) the overhead of the funtion calls alone vs directly access the data structure was twice as slow. I tested by actually creating the accessors without the use of AUTOLOAD. But that is the price to pay for OOP modularity, and generally well worth the performance price.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found