in reply to Optimizing a large project.

3. We use SWIG to talk to shared memory. Does anyone have any idea the difference in performance between hand rolling XS over SWIG for reading attributes off a C Structure? (or is there some even "better" way to do this kind of thing that I've never heard of?)

SWIG wrappers are very inefficient!

The way it uses a tie interface to expose C struct attributes, and the double wrapping of objects it performs, makes it more than an order of magnitude slower than an equivalent hand-crafted XS interface (note that I am talking exclusively about the wrapping, obviously, the C functions behind, take the same time no matter if you use SWIG or XS!).

Replies are listed 'Best First'.
Re^2: Optimizing a large project.
by dextius (Monk) on Jun 12, 2008 at 17:57 UTC
    Awesome, thanks for your input... /me breaks open copy of "Extending and Embedding Perl"..

      I'm no XS or Inline::C guru. Take the following comments with a grain (or more) of salt.

      I've used Inline::C a few times and it is pretty slick for quickly hacking together a bit of C code and Perl. Couldn't be any easier.

      I understand that I::C autogenerates XS code behind the scenes. I have seen multiple recommendations here that a good way to get up and running with XS is to use I::C to generate a basic chunk of XS and then switch to pure XS for production use.

      I've never needed to take this final step with my I::C hackery, but based on other reports it's worth investigating.

      Some other tools are mentioned in this thread.


      TGI says moo