I currently have two issues that are bothering me with partcl:

1) Speed.

We are getting slower (though we're getting MUCH more feature
complete). While speed is not our number 1 priority (in fact, it's pretty
much at the bottom of the barrel), having a zippier
tcl.pbc will improve development, as we can run the test suite faster.
(this is mainly tcl's test suite I'm talking about here.)
The problem here is that we don't know exactly where our bottlenecks are, where best to concentrate our optimizations. Parrot provides opcode level
profiling, but a more helpful report for me would be based on parrot
subroutines. e.g. how much time was spent calling '__script' in the '_tcl'
namespace? (per invocation, how many invocations, etc.)

2) implementing [trace] (http://www.tcl.tk/man/tcl8.5/TclCmd/trace.htm).

[trace] provides a way to run code before or after invocation of sub. [1]
There's even a facility to run something before or
after each line (of Tcl) in a sub. While it would be possible to implement
the basic functionality by wrapping existing subs in other subs,
I'm not sure that would help with
[trace info], which provides a way to report on all the traces that are
currently set. (We could hack this into a hidden global, as we do for tcl's ability to report on a function declaration: but that's a hack that I'd like
to undo at some point).

...

So I was looking at these two items today and realized (as the clever
reader already has) that if there is a parrot-level way to handle
setting [traces] for parrot subroutines, then implementing #1 becomes a
simple matter of programming: walk the namespaces you're interested in
to find all the subs, and add enter/exit traces to them that keep track of
the invocation time, and then report on program exit what you've found.

In fact, I could use partcl itself to do my own benchmarking if this
mechanism was in place.

At runtime, it would be nice to be able to declare the hooks to call pre
and post sub invocation. I propose [2] we call these:

trace_sub $P1, $P2, $I3

where $P1 is the original sub, $P2 is our invokable sub that we call
before or after, and $I3 is a parameter indicating enter, leave, etc.

$P2 here would be passed two parameters, the name of the sub that it was
being invoked on behalf of, and the type of operation that is occurring
(enter, leave, etc.)

Would also be nice to be able to declare these at compile time, something like:

.HLL tcl, 'tcl_group'

.sub joe
  .param string proc_name
  .param int operation
  if operation == .TRACE_ENTER goto enter
  print "leaving "
  goto done
enter:
  print "entering "
done:
  print "ing "
  say proc_name
.end

.sub bob :enter joe :leave joe
  say "whoa."
.end


Which would, when invoking bob(), print:

entering tcl::bob
whoa.
leaving tcl::bob

(with appropriate handwaving as to how a fully qualified procedure name
with namespace stringifies).

Thoughts? If this seems a reasonable approach, I can spec out more opcodes, PIR sugar, etc., to handle all the subroutine related tracing required by
Tcl.

[1] Note that [trace] also does variable tracing for set/get/hash access. I think the mechanism for sub-based tracing and variable based tracing is
going to be different, so I'm not addressing the variable based one here
(not to mention I don't need that for benchmarking).

[2] Repaint bikeshed as necessary.

--
Will "Coke" Coleda
[EMAIL PROTECTED]


Reply via email to