[Dbix-class] Rapid Data Extraction
Zbigniew Lukasiak
zzbbyy at gmail.com
Tue Jan 12 10:38:16 GMT 2010
Just shooting blindly, but if you are so speed concerned - then
perhaps you could try
http://search.cpan.org/~frew/DBIx-Class-0.08115/lib/DBIx/Class/ResultClass/HashRefInflator.pm
?
Z.
On Tue, Jan 12, 2010 at 10:26 AM, Ovid <publiustemp-dbic at yahoo.com> wrote:
> Relevant facts:
>
> 1. bbc.co.uk is the fifth most popular web site in the UK (http://www.alexa.com/siteinfo/bbc.co.uk)
> 2. We use DBIx::Class extensively on our iPlayer backend.
> 3. Performance is critical.
>
> Code in our Web templates is not allowed to touch the database. Thus, for each DBIx::Class result object, we extract the relevant data and put it into a simple object. The relevant code looks like this:
>
> sub _init_from_real_thing {
> my $self = shift;
>
> # from _real_thing
> $self->$_( $self->_dbic->$_ ) for $self->attributes;
>
> return $self;
> }
>
> Creating one of these objects takes approximately 50 milliseconds. Each of the individual channels or episodes you see on http://www.bbc.co.uk/iplayer/ represents one of these blocks. If we create 50 of these objects, that's 2.5 seconds -- way too long.
>
> As a performance hack, I'd like to experiment with something like this:
>
> sub _init_from_real_thing {
> my $self = shift;
>
> my @attributes = $self->attributes;
> @{$self}{@attributes} = @{$self->_dbic->{_column_data}}{@attributes};
>
> return $self;
> }
>
> Using the slices is a horrible encapsulation violation. I can deal with that on our side, but not on the dbic side. Is there a clean way of fetching all of that at once?
>
> If you're curious, here's my benchmark:
>
> Rate methods slice
> methods 26954/s -- -71%
> slice 94340/s 250% --
>
> Using the slice is almost four times faster than the "clean" strategy.
>
> Cheers,
> Ovid
> --
> Buy the book - http://www.oreilly.com/catalog/perlhks/
> Tech blog - http://use.perl.org/~Ovid/journal/
> Twitter - http://twitter.com/OvidPerl
> Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/
More information about the DBIx-Class
mailing list