While we need to consider ways to make EHs less expensive, a cheap and easy
gain comes from adding the init_pmc() VTABLE entry in the attached patch. For
an EH which handles only a single type of exception, we can rewrite code from:
.sub "fib" :subid("11_1259711141.42547") :outer("10_1259711141.42547")
.param pmc param_16
.annotate "line", 3
new $P15, 'ExceptionHandler'
set_addr $P15, control_14
$P15."handle_types"(58)
push_eh $P15
...
.end
... to:
.sub "fib" :subid("11_1259711141.42547") :outer("10_1259711141.42547")
.param pmc param_16
.annotate "line", 3
$P1 = box 58
new $P15, 'ExceptionHandler', $P1
set_addr $P15, control_14
push_eh $P15
...
.end
Note that this replaces a method call with Integer boxing. The resulting code
(PIR generated by a Fibonacci benchmark written with NQP-rx) runs 22.166%
faster.
It might be useful to extend the initializer to take a PMC array as well, when
the EH can handle multiple types of exceptions, but most of the uses I've seen
in NQP-rx so far handle only one type of exception.
-- c
diff --git a/src/pmc/exceptionhandler.pmc b/src/pmc/exceptionhandler.pmc
index acc5e66..3f3fc28 100644
--- a/src/pmc/exceptionhandler.pmc
+++ b/src/pmc/exceptionhandler.pmc
@@ -55,6 +55,12 @@ Initializes the exception handler.
PObj_custom_mark_SET(SELF);
}
+ VTABLE void init_pmc(PMC *init) {
+ PMC * const types = pmc_new(interp, enum_class_FixedPMCArray);
+ VTABLE_set_integer_native(interp, types, 1);
+ VTABLE_set_pmc_keyed_int(interp, types, 0, init);
+ }
+
/*
=item C<void mark()>
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev