Archive for September, 2009

Benchmarking some ORLite variants

It would be nice if I could get my ORLite performance boost without really changing the (undocumented) API. So I got one more idea: Do the slicing in the ORLite generated code. It’s available in a new branch on GitHub.

To benchmark all three solutions I used a variant of CPANDB::Dependecy::csv():

sub csv {
    my $class = shift;
    for my $edge ( $class->select ) {
        my $foo = $edge->distribution . "\t" . $edge->dependency . "\n";
    }
}

My::Plain->begin;
My::Unsliced->begin;
My::SelfSlice->begin;

cmpthese( -30, {
    plain => sub { csv("My::Plain::Dependency") },
    unsliced => sub { csv("My::Unsliced::Dependency") },
    selfslice => sub { csv("My::SelfSlice::Dependency") },
});

Unfortunately it seems like both having DBI doing the slicing and doing it myself costs roughly the same:

            Rate selfslice     plain  unsliced
selfslice 1.61/s        --       -1%      -41%
plain     1.64/s        2%        --      -40%
unsliced  2.71/s       68%       66%        --

So I probably end up making some sort of ORLite subclass as Adam Kennedy suggested in a comment.

Comments

Optimizing ORLite.pm

While profiling some code making heavy use of Adam Kennedy’s ORLite module for accessing a SQLite database I found that most of my time was spend in DBI.pm.

Sorted by inclusive time (ie. including time spent in subroutines) two non-XS functions stood out: selectall_arrayref and fetchall_arrayref. Looking a the code both of these functions had a comment stating that a C implementation existed in Drivers.xst and the comment at selectall_arrayref further said that the Perl version is used as a fallback if a slice is given

So could I get away with the slicing?

Turned out to quite easy. Just use array refs as objects instead of the usual hash refs.

The run time of the select() method provided by ORLite went from 344µs/call to 162µs/call on average. And as my test data makes at roughly 100000 select() calls this is a quite noticeable speedup. All included my running time (under Devel::NYTProf) improved from 400 seconds to 340 seconds.

Unfortunately I have to be able to update the state of my ORLite generated objects. This was easy while the objects was blessed has refs. Array refs are not as easy to update. The easy solution was to make the simple non-fk accessors to be lvalue subroutines.

Comments (1)

HTTP::Engine is great

For simple web-based services I usually just use Perl and CGI.pm. After having read a bit about HTTP::Engine I tried it for a simple project yesterday. Beside my own logic it only took a few line of code to have a stand alone HTTP server for my service.

My colleague needed it to be served from the same Apache server as the rest of his webapplication. Some tiny changes and my stand alone server was transformed into a plain CGI script. When we going to deploy the script I’m guessing we make some tiny changes and have it running as a mod_perl module.

Try it for you next project! Even if you usually just use CGI.pm.

Comments (1)

DF er en trussel mod demokratiet!

I deres nyeste rekvalmefremstød illustrerer Dansk Folkeparti forskellem mellem demokrati og massediktatur.

Dansk Folkeparti taler ikke for demokrati. Demokrati baserer sig på frihed og lighed. De stiller sig som fortalere for den mest xenofobiske form for massediktatur.

Sig fra over for Dansk Folkepartis drømme om massediktaturets tyrani!

Comments