in reply to Re: When every microsecond counts: Parsing subroutine parameters
in thread When every microsecond counts: Parsing subroutine parameters

XS has a surprising amount of overhead per call copying parameters in and out. When I was writing Lingua::Stem I was able to achieve 80% of the speed of Lingua::Stem::Snowball (which uses XS) for stemming in place and actually beat Lingua::Stem::Snowball by 30% for large straight list processing.
  • Comment on Re^2: When every microsecond counts: Parsing subroutine parameters

Replies are listed 'Best First'.
Re^3: When every microsecond counts: Parsing subroutine parameters
by Joost (Canon) on May 17, 2008 at 20:48 UTC
    All parameter passing / subroutine calls involving perl are relatively slow, and conversion to and from C types can probably make XS even slower than pure perl if used naively. The best way to use XS/C is to reduce the number of calls back and forth (IOW, move your iterations to C code, don't loop over XS calls where speed really matters). C compilers are very good at inlining and otherwise optimizing subroutine calls. Perl isn't, really - even though it's overall pretty damn fast compared to some other "scripting" languages I could mention.