Using "static" in Perl Extensions

Discussion in 'Perl Misc' started by Mark Shelor, Feb 7, 2004.

  1. Mark Shelor

    Mark Shelor Guest

    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
    Mark Shelor, Feb 7, 2004
    #1
    1. Advertising

  2. Mark Shelor

    Ben Morrow Guest

    Mark Shelor <> wrote:
    > 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

    --
    Although few may originate a policy, we are all able to judge it.
    - Pericles of Athens, c.430 B.C.
    Ben Morrow, Feb 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. www.MSmobiles.com
    Replies:
    1
    Views:
    365
    Teemu Keiski
    Jul 18, 2004
  2. Tim Fuehner
    Replies:
    0
    Views:
    395
    Tim Fuehner
    Dec 8, 2003
  3. Ricardo Palomares Martinez
    Replies:
    2
    Views:
    376
    david.karr
    Apr 28, 2007
  4. Daniel Berger

    Static functions, extensions, linkage

    Daniel Berger, Aug 2, 2006, in forum: Ruby
    Replies:
    6
    Views:
    166
    Tim Hunter
    Aug 2, 2006
  5. Alex Young
    Replies:
    4
    Views:
    154
    Alex Young
    Apr 14, 2011
Loading...

Share This Page