develooper Front page | perl.dbi.dev | Postings from February 2012

Misc DBI_dispatch speedup patches

From:
Dave Mitchell
Date:
February 24, 2012 08:27
Subject:
Misc DBI_dispatch speedup patches
Message ID:
20120224162708.GN2998@iabyn.com
The 8 attached patches (to be applied in sequence) all provide tweaks,
cleanup, or otherwise attempt to make DBI_dispatch go a little bit faster.
This speedups are all relatively minor, and my timings show the
cumulative speedup for my standard fetch() test loop is somewhere between
0% and 9% based on the perl version (better for newer perls), but
generally with a variation of around 5% between test runs. So take with a
pinch of salt.

These patches should be possible to apply without my DBIS patch having
been applied (although some hand merging might be necessary).

The first patch is the biggest. It moves the method lookup cache into the
dbi_ima_t struct (rather than being directly attached to magic).
This is what you originally suggested I do, but I couldn't do it because
the any_ptr field in the CV wouldn't be properly duped or freed.
I subsequently realised that I could get round this by attaching magic
(with dup and free functions), which administers to the any_ptr field.
This makes things a lot simpler.
It was then made more complex again by the fact that in perls < 5.8.9, the
new any_ptr field is overwritten after the magic dup handler is called :-(
So there's some special ifdef'd code to handle this.

This patch also means that *all* CVs are given dbi_ima_t structure when
installed, rather than only the ones with attributes.

The second patch just inlines the method cache lookup, now that it's
simpler.

The third makes use of ima always being available, by pre-calculating
type of method at install time; i.e. this

    *meth_name =='F' && strEQ(meth_name,"FETCH")

becomes

    meth_type == methtype_FETCH

The fourth does a shortcut for mg_find, similar to that done in
dbih_getcom2().

The fifth follows on from that by eliminating the is_FETCH var.

The sixth slightly tweaks where qsv (quick SV) is tested.

The seventh removes some GV tests relating to the method to be called.
It used to do isGV(imp_msv) before accessing  GvCV(imp_msv); but since an
earlier bit of code accesses GvCV(imp_msv) before the test, I assume
that either the test is redundant and imp_msv is always a gv, or
that it might not be a GV and it's just a miracle that the code hasn't
SEGVed in the past (if the latter, then my patch is wrong).

The eighth optimises the stack handling done before/after the inner method
call in the XS case.

Dave


-- 
print+qq&$}$"$/$s$,$a$d$g$s$@$.$q$,$:$.$q$^$,$@$a$~$;$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:17a2~2.3@3;^2dg3q/s"&=~m*\d\*.*g




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About