Using "static" in Perl Extensions

M

Mark Shelor

I've encountered a troublesome inconsistency in the Perl extension I've
written for CPAN (Digest::SHA). The problem involves the use of a
static array within a performance-critical transform function. When
compiling under gcc on my big-endian PowerPC (Mac OS X), declaring this
array as "static" DECREASES the transform throughput by around 5%.
However, declaring it as "static" on gcc/Linux/Intel INCREASES the
throughput by almost 30%.

I would prefer that the array not be "static" so that the underlying C
function will be thread-safe. However, giving up close to 30%
performance on gcc/Linux/Intel is unacceptable for a digest routine,
whose value is often closely tied to speed.

Can anyone enlighten me on this mystery, and recommend a simple, clean,
portable way to assure good performance on all host types?

TIA, Mark
 
B

Ben Morrow

Mark Shelor said:
I've encountered a troublesome inconsistency in the Perl extension I've
written for CPAN (Digest::SHA). The problem involves the use of a
static array within a performance-critical transform function. When
compiling under gcc on my big-endian PowerPC (Mac OS X), declaring this
array as "static" DECREASES the transform throughput by around 5%.
However, declaring it as "static" on gcc/Linux/Intel INCREASES the
throughput by almost 30%.

I would prefer that the array not be "static" so that the underlying C
function will be thread-safe. However, giving up close to 30%
performance on gcc/Linux/Intel is unacceptable for a digest routine,
whose value is often closely tied to speed.

Can anyone enlighten me on this mystery, and recommend a simple, clean,
portable way to assure good performance on all host types?

I don't know about the speed issues, but static data in extensions
*really* ought to use the MY_CXT stuff, so it ends up threadsafe. See
"Safely Storing Static Data in XS" in a recent perlxs, and get a
recent ppport.h if your perl doesn't support it.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top