$   parrot -p lex.pasm # [1]
0.041843
0.810558
...
  CODE   OP FULL NAME            CALLS  TOTAL TIME    AVG TIME
  -----  -----------------     -------  ----------  ----------
   1138  Exception               10000    0.697707    0.000070

You for sure can now say, that my exception handling stuff sucks. But that's using only standard features: A PerlHash class which is the Exception object, the exception handler is a Continuation - that's all.

The main time consuming task is just constructing the exception object. Real objects might be faster here, but all the runtime construction of such complex objects suffer of the same problem: we don't have constant and cached strings (meaning currently: each hash key is a new string) and we don't have means to create constant shared PMCs at runtime.

Accessing a attribute/property/hash entry like "_message" at runtime currently needs the construction of a new Key PMC ...

However the exception object will look like finally, I expect it to be a singleton of a class hierarchy representing our exception classes, that can be put in place with one constant_table lookup.

If the exception handler wants to reuse the exception beyond a further exception it throws or that might get thrown (and is resumable), the handler can clone the exception before.

leo

[1]
$ cat lex.pasm
        new_pad 0
        new P0, .PerlInt
        set P0, 42
        store_lex -1, "yep", P0

        set I0, 10000
        time N0
lp1:
        find_lex P1, "yep"
        dec I0
        if I0, lp1
        time N1
        sub N2, N1, N0
        print N2
        print "\n"

        newsub P3, .Exception_Handler, _failed
        set_eh P3

        set I0, 10000
        time N0
lp2:
        find_lex P1, "no"
ret:
        set_eh P3
        dec I0
        if I0, lp2
        time N1
        sub N2, N1, N0
        print N2
        print "\n"
        end
_failed:
        set P0, P5["_invoke_cc"]
        invoke



Reply via email to