[RFC] Constant PMCs in PBC

Patrick R. Michaud pmichaud at pobox.com
Mon Dec 7 13:58:16 UTC 2009


On Mon, Dec 07, 2009 at 01:14:43AM -0800, chromatic wrote:
> A good optimization step is enabling the use of compile-time constant PMCs in 
> bytecode.  Consider this code generated by NQP-rx:
> 
> 	.namespace []
> 	.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
> 
> The ExceptionHandler in $P15 is (effectively) constant and won't change 
> throughout the invocation of the program.  

I've already started a patch to PCT that will cache the ExceptionHandler
the first time the sub is entered and then re-use that handler on
subsequent invocations of the sub.  This saves us the overhead of
creating the EH on each invocation, at the cost of the cache lookup
and test.  

This feature is also being generalized into PAST itself, so that
*any* constant value or structure can be computed and cached on 
first use at runtime and then re-used from the cache on subsequent 
uses.  The expensive part then becomes the cache itself; at the moment 
I'm placing values into a private root namespace, but looking things up
in root namespaces is also a little on the expensive side (although not
nearly as expensive as creating the EH in the first place).

The other expensive part is the push_eh instruction -- it appears to
involve creating a ResizablePMCArray on each invocation.  So another
improvement might be to allow the *handlers context attribute to point
to _either_ a single handler or an RPA of handlers; the first invocation
of push_eh in a context simply sets *handlers to the EH, and setting
a second handler in a context promotes *handlers into an array.  For
subs that only have at most one handler in effect at a time (this is
the great majority of subs), this could be a significant improvement.

Pm


More information about the parrot-dev mailing list