[Koha-bugs] [Bug 30169] Prefetching is expensive for performance

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Feb 24 17:17:12 CET 2022


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30169

--- Comment #5 from Martin Renvoize <martin.renvoize at ptfs-europe.com> ---
#!/usr/bin/env perl

use strict;
use warnings;

use Benchmark qw/cmpthese timethese/;
use Koha::Libraries;
use Koha::Database;

my $schema = Koha::Database->schema;

cmpthese(
    -100,
    {
        kohaPrefetch => sub {
            for ( my $i = 0 ; $i < 250 ; $i++ ) {
                my $checkout = Koha::Checkouts->find( { itemnumber => 10 },
                    { prefetch => [ 'item', 'patron' ] } );
                my $item_id   = $checkout->item->itemnumber;
                my $patron_id = $checkout->patron->borrowernumber;
            }
        },
        kohaJoin => sub {
            for ( my $i = 0 ; $i < 250 ; $i++ ) {
                my $checkout  = Koha::Checkouts->find( { itemnumber => 10 } );
                my $item_id   = $checkout->item->itemnumber;
                my $patron_id = $checkout->patron->borrowernumber;
            }
        },
        dbicPrefetch => sub {
            for ( my $i = 0 ; $i < 250 ; $i++ ) {
                my $checkout =
                  $schema->resultset('Issue')->find( { itemnumber => 10 },
                    { prefetch => [ 'item', 'patron' ] } );
                my $item_id   = $checkout->item->itemnumber;
                my $patron_id = $checkout->patron->borrowernumber;
            }
        },
        dbicJoin => sub {
            for ( my $i = 0 ; $i < 250 ; $i++ ) {

                my $checkout =
                  $schema->resultset('Issue')->find( { itemnumber => 10 } );
                my $item_id   = $checkout->item->itemnumber;
                my $patron_id = $checkout->patron->borrowernumber;
            }
        }
    }
);

Alternatively, for instantiation speed.. the prefetch creates a bigger,
heavier, object and so clearly will be slower than without.

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list