Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of IlyaM (2933)

Wednesday April 02, 2003
05:02 AM

Class::MethodMaker in XS

[ #11397 ]
I wonder why nobody yet tried to write something like Class::MethodMaker in XS? I tried to compare pure Perl accessor methods and their XS analogs and the latest was noticibly faster. It would be very nice if we had a CPAN module which provides basic constuctor, accessor and other common methods implemented in XS so everybody could benefit from these speed gains in their Perl OO code without resorting to writting XS themselves.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I thought about doing this a while ago. Another advantage being that you could get around perl's crappy OO system by using proper structs.

    Unfortunately I stopped at the "thinking" stage :-/
  • So how would it work? Let's say I do:

      use Class::XSMethodMaker
         get_set => [qw(foo bar)];

    Does this mean that XS code for foo() and bar() are generated and compiled on the fly? Or does it just do what Class::MethodMaker does and generate closures bound to *foo and *bar? Can you generate a closure in XS which closes around C code?


    • Tough question. One possible solution is pregenerating XS code given a list of fields. Another even generating C code on fly what should not be very hard using Inline::C. Anyway it doesn't seem a proper way to me and I'd like to be able simulate closures in C code. No idea how though. Not sure that it is even possible.

      Ilya Martynov ( [])

  • I was always under the impression that perl method dispatch was what caused things to take such a long time. If that's the case, then surely having methods execute faster once they've been dispatched to, wouldn't help much.

    Or am I missing the point (or should that be the profile?) here?


    • Perl method dispatch is slow but perl code for accessors is not fast also. Here an example (one accessor is implemented in Perl and another in C with help of Inline::C):

      use Benchmark;

      my $obj = A->new;

      &nb sp;         { pure_perl => sub { $obj->field1($obj->field1) },
                  inline_c  => sub { $obj->field2($obj->field2) }


      Ilya Martynov ( [])