[Dbix-class] Problem using DBIx::Class::ResultClass::HashRefInflator

Jochen Luig jochen.luig at skytel.de
Mon Jan 12 11:27:42 GMT 2009


Hi,

I tried to speed up a query using
DBIx::Class::ResultClass::HashRefInflator recently. Apparently there was
no performance gain, so I did the benchmark you can find at the end of
this message (I only did 50 iterations because I didn't want to wait
hours for a result and the performance gap is quite obvious even for
very few iterations). The query used below returns 2403 rows.
Also the inflate_result method of a related class crashed when I didn't
select the corresponding foreign key column which implies that object
creation took place. BTW, I get similar results when passing the
result_class as an attribute.

Then I found
http://lists.scsys.co.uk/pipermail/dbix-class/2008-February/005733.html
which would explain my observations. Has the patch discussed there
already been applied? I couldn't find it mentioned in the CHANGES file
of DBIx::Class.
So I'd like to know if I just misunderstood the docs or if I should
resort to plain DBI for performance critical queries.
Am I doing anything wrong in my code or is this just the behaviour of
DBIx::Class::ResultSet?

Bye,

Jochen


use strict;
use warnings;

use Benchmark qw( cmpthese );
use DBI;
use lib '../MyApp/lib/';
use MyAppDB;


my $dbh = DBI->connect(...);
my $schema = MyAppDB->connect(...);

cmpthese( 50, { dbic => \&dbic, hashrefinflator =>
\&dbic_HashRefInflator, plain_dbi => \&plain_dbi });

sub dbic {
    my @req = $schema->resultset('MyAppDB::Request')->search(
        {message_id => \"IN (173, 174, 171, 1, 168, 144, 177, 111, 178,
172, 95, 196, 179)"},
        {
         columns=>[qw/ id message_id created status amount /] 
        },	
        );
}

sub dbic_HashRefInflator {
    my $resultset = $schema->resultset('MyAppDB::Request');

$resultset->result_class('DBIx::Class::ResultClass::HashRefInflator');
    my @req = $resultset->search(
        {message_id => \"IN (173, 174, 171, 1, 168, 144, 177, 111, 178,
172, 95, 196, 179)"},
        {
         columns=>[qw/ id message_id created status amount /] 
        },	
        );
}

sub plain_dbi {
    my $query = $dbh->prepare('SELECT id, message_id, created, status,
amount FROM requests WHERE message_id IN (173, 174, 171, 1, 168, 144,
177, 111, 178, 172, 95, 196, 179)');
    my $result = $query->execute();
}




            (warning: too few iterations for a reliable count)
                  s/iter hashrefinflator            dbic       plain_dbi
hashrefinflator     6.30              --             -0%           -100%
dbic                6.27              0%              --           -100%
plain_dbi       1.40e-03         449729%         447671%              --







More information about the DBIx-Class mailing list