develooper Front page | perl.perl5.porters | Postings from October 2003

perl's internal usage of dTHX; is a bad idea

Thread Next
Stas Bekman
October 23, 2003 16:13
perl's internal usage of dTHX; is a bad idea
Message ID:
Frankly I don't understand why internally Perl uses functions which aren't 
prototyped with (pTHX_ ...), and call dTHX; instead. Besides forcing on the 
application the overhead of calling PERL_SET_CONTEXT() every few millisecs in 
the env with multiple perl instances, any application always has an overhead 
of retrieving PERL_GET_CONTEXT. A good example of such a function is: 
Perl_safesysmalloc, which is called very often. There should be an alternative 
function which accepts the context as an argument, when it's available (which 
is true in most cases in perl guts).

Ideally Perl internals shouldn't rely on the user to call PERL_SET_CONTEXT() 
and call it by itself only when needed. But I realize that it doesn't always 
work, e.g. when a redefined malloc is called by other parts of the non-perl 

I was told that calls to PERL_SET_CONTEXT/PERL_GET_CONTEXT are especially 
expensive in the multithreaded environment, because of the thread local 
storage management overhead. I would be interested to hear more about this 
from the threads experts.

I wonder whether someone has benchmarked that overhead in the threaded 

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About