Stories
Slash Boxes
Comments
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 jjore (6662)

Wednesday October 10, 2007
02:11 AM

Making my methods 13x faster

[ #34643 ]

Without any explanation:

           Rate  perl    xs   ops
perl  1585581/s    --  -65%  -93%
xs    4573187/s  188%    --  -80%
ops  22482894/s 1318%  392%    --

http://diotalevi.isa-geek.net/~josh/tmp/bench

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • OK, so the result looks impressive, but why not explain it? My knowledge of Perl internals is poor enough that I don't understand your code. I assume that you've disabled or skipped something which is ordinarily assumed, thus meaning that if someone wanted to use your technique, they'd have to accept certain constraints on their OO code?

    • It is the long rumored "my Dog $spot" optimization. If I know the type of my lexical at compile-time then I can substitute a custom opcode that implements my method call.

      Also, I was tired. It was 1am.
      • So this is something you could use to speed up AI::Prolog quite a bit, eh? Or is this global in effect and wouldn't allow folks to typed declarations? Is this only for kurila?

        • kurila? No. I've never used that. This runs on 5.8+. You could use this technique on anything where it is acceptable to bake in the object implementation. My guess is that this must be swappable for perl-code so that perl's sometimes incredible flexibility can be re-enabled. Using this optimization prevents things like duck typing from working.
        • Sorry for the barrage of silly questions. Is this sort of like the Perl equivalent of declaring a class as "Final" (as Java does, for example) for performance benefit reasons?

          • I don't know about the performance implications of declaring a final class in Java.
            • Who cares about the performance in Java. The question is whether it is comparable with declaring a class final.

              • Yes, generally, it is. Though the declaration happens inside out. In Java I suppose you would declare this about your class and all your users would see the effect.

                In Perl, with this change, you'd only see the effect if you'd compiled your class prior to compiling code that would later use it and also annotated your user code with

                my Dog $pot

                the syntax. This isn't strictly tied to the

                my Dog $pot

                syntax. The key is the annotation about a particular

                $spot

                being one that can be messed with. I could


      • Schweeeeet!!

        I'll have to stare at it a while before I understand it, but I was gunning for something similar with my Code::Splice thingie. Rather than using those type declarations, I was just going to do static analysis of the code to find out where the optimization (in my case, of inlining method bodies) could safely be done. Huge program to be optimized, so an automatic approach was needed. I was fired before I could finish with only two weeks of brainpower on it. Gah. It seems like this would avoid