note
BrowserUk
<blockquote><i>(So, BrowserUk, it looks like this stub wasn't optimized away.)</i></blockquote>
<p>Hm. If you look above, you'll see that the 'call' from the XS wrapper to <c>void test( SV *sv ) { ++i; }</c> gets inlined to just 1 instruction:<code>
67 ; 31 : test(sv);
68
69 inc DWORD PTR i
</code>
<p>However, defining PERL_NO_GET_CONTEXT doesn't change a thing in the generated assembler. Of course, that is pre-optimisation code, so your timings may be a better indicator.
<P>That said, I think you would be better off looking at ways to try and move some or all of your loop into C, rather than trying to optimise the calls from Perl to C.
<p>What I mean is, if you are calling from Perl -> C 10e8 times, then your Perl code must consist of one or more loops. Whilst there is obviously some savings to be had by minimising the perl -> C -> perl transitions, there is (probably) a much larger saving to be had by moving the loop into C and avoiding all/or a large number of those transitions.
<P>As an extreme example, [node;//1216742|the deBruijn sequence generator I recently ported from Python to Perl] takes 1587 seconds to generate the de Bruijn sequence for 8-char substrings from a 10-char alphabet; but when ported to C, that drops to 0.57 seconds ( a 99.96% reduction!):<code>
C:\test>DeBruijnX -N=8 -ALPHA=0123456789
Took: 1586.944328 secs
100000000
Took: 0.579065 secs
100000000
</code>
<p>And a very large part of that massive saving is avoiding the perl function call overhead of the 16 million recursive function calls involved:<code>
#! perl -slw
use strict; # use Config; print $Config{ ccflags };
use Inline C => Config => BUILD_NOISY => 1; #, CCFLAGS => $Config{ ccflags } . "/link /FAs";
use Inline C => <<'END_C', NAME => '_deBruijn', CLEAN_AFTER_BUILD =>0;
#define PERL_NO_GET_CONTEXT 1
int n, iseq;
STRLEN k;
char *seq, *a;
void dbc( int t, int p ) {
int i;
if( t > n ) {
if( n % p == 0 )
for( i = 1; i <= p; ++i )
seq[ iseq++ ] = a[ i ];
}
else {
a[ t ] = a[ t - p ];
dbc( t+1, p );
for( i = a[ (t - p) ] + 1; i < k; ++i ) {
a[ t ] = i;
dbc( t+1, t );
}
}
}
SV *deBruijnC( SV *svAlphabet, SV *len ) {
int i;
char *alphabet = SvPV( svAlphabet, k );
n = (int)SvIV( len );
iseq = 0;
Newxz( seq, (int)pow( (double)k, (double)n), char );
Newxz( a, k * n, char );
dbc( 1, 1 );
for( i = 0; i < iseq ; ++i ) {
seq[ i ] = alphabet[ seq[ i ] ];
}
return newSVpv( seq, iseq );
}
END_C
</code>
<p>Defining PERL_NO_GET_CONTEXT doesn't stop it from running, but it doesn't improve performance one iota.
<div class="pmsig"><div class="pmsig-171588">
<hr />
<font size=1 >
<div>With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'</div>
<div>Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.</div>
<div>"Science is about questioning the status quo. Questioning authority". [http://www.theregister.co.uk/2016/11/02/complexity_in_it/|The enemy of (IT) success is complexity.]</div>
<div>In the absence of evidence, opinion is indistinguishable from prejudice.
<span>[https://www.theregister.co.uk/2017/04/10/mark_shuttleworth_says_some_free_software_contributors_are_deeply_anti_social/|Suck that fhit]</span> </div>
</font>
</div></div>
1216682
1216799