Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

avoid dTHX where possible (it's relatively expensive)

6 views
Skip to first unread message

Nicholas Clark

unread,
May 21, 2014, 6:00:57 AM5/21/14
to dbd...@perl.org
Attached are two patches that remove use of dTHX in functions in quote.c
and types.c

dTHX is ithreads only, but relatively expensive, as it needs to make a
function call to retreive a value from thread local storage. It's much
better to pass that value as a function parameter, as the caller will have
it already.

Tested for (almost) everything ithreads and not from 5.8.1 to 5.18.2

I can't see how to make the same change to dbdimp.c without also changing
Driver.xst to optionaly support it.

Nicholas Clark
0001-Pass-the-interpreter-struct-into-quote-functions-ins.patch
0002-Remove-references-to-the-interpreter-struct-in-types.patch

Tim Bunce

unread,
May 22, 2014, 5:49:39 AM5/22/14
to Nicholas Clark, dbd...@perl.org
On Wed, May 21, 2014 at 11:00:57AM +0100, Nicholas Clark wrote:
> Attached are two patches that remove use of dTHX in functions in quote.c
> and types.c
>
> dTHX is ithreads only, but relatively expensive, as it needs to make a
> function call to retreive a value from thread local storage. It's much
> better to pass that value as a function parameter, as the caller will have
> it already.

Thanks Nicholas!

> I can't see how to make the same change to dbdimp.c without also changing
> Driver.xst to optionaly support it.

That would be tricky.

The handle data structure includes the PerlInterpreter* of the thread
that created it https://github.com/perl5-dbi/dbi/blob/master/DBIXS.h#L95

and the DBI's method dispatcher ensures that DBI methods are only called
in the same thread that created them, i.e.

https://github.com/perl5-dbi/dbi/blob/master/DBI.xs#L3300

So, for methods that are passed a handle and already declare and set a
local imp_xxh pointer (e.g., D_imp_sth(sth);) I wonder if it would be
worth defining a macros to get the thread pointer from the handle.
Something like dTHX_from_imp_xxh(imp_xxh);

Tim.

Nicholas Clark

unread,
May 23, 2014, 3:37:31 AM5/23/14
to Tim Bunce, dbd...@perl.org
I don't think that this will work

#define D_imp_sth(h) D_impdata(imp_sth, imp_sth_t, h)
#define D_impdata(name,type,h) type *name = (type*)(DBIh_COM(h)

#ifdef IN_DBI_XS /* get Handle Common Data Structure */
#define DBIh_COM(h) (dbih_getcom2(aTHX_ h, 0))
#else
#define DBIh_COM(h) (DBIS->getcom(h))
#define neatsvpv(sv,len) (DBIS->neat_svpv(sv,len))
#endif

You need a copy of my_perl (that aTHX_) to get the to data structure that
contains my_perl (if I follow the macros correctly)

Nicholas Clark

Tim Bunce

unread,
May 23, 2014, 8:24:51 AM5/23/14
to Nicholas Clark, Tim Bunce, dbd...@perl.org
Yes, the key part is that within a driver (DBIS->getcom(h)) is used
but DBIS is defined as (*dbi_get_state(aTHX)).

Ho hum. Thanks.

Tim.
0 new messages