These figures are consistent with another rather large Class::DBI project I'm involved with.

One of the things you could do is to subclass the _mk_column_accessors method, e.g.:

sub _mk_column_accessors { my $class = shift; my @new = grep {!exists &{$class."::$_"}} @_; # remember new ones $class->SUPER::_mk_column_accessors( @_ ); # accessors + mutators # Redefine accessors to be very lean no warnings 'redefine'; no strict 'refs'; foreach (@new) { my $method = $class."::$_"; my $old = \&$method; *$method = sub { # if not available yet, got fetch with normal accessor return $old->( @_ ) unless exists $_[0]->{$_}; $_[0]->{$_}; }; } } #_mk_column_accessors

Further optimizations with the accessors could be made if you know 100% sure that when a subclss Class::DBI object is created, all the fields are fetched from the database (bij setting all of the fields to be "Essential"). Something like:

sub _mk_column_accessors { my $class = shift; eval "sub ${class}::$_ { \$_[0]->{'$_'} }" foreach grep {!exists &{$class."::$_"}} @_; $class->SUPER::_mk_column_accessors( @_ ); } #_mk_column_accessors

Please note that I've used a string eval here for a reason: benchmarks have shown that accessors created that way are the fastest accessors possible (just as if writing them manually). All other solutions use a closure, which are inherently slower. And since speed is what you're interested in here... ;-)

Hope this helps.

Liz


In reply to Re: dprofpp -- now what? by liz
in thread dprofpp -- now what? by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.