[MLton-user] Stack Traces

Matthew Fluet fluet at tti-c.org
Fri Mar 23 09:17:05 PST 2007


Neal Glew wrote:
> What are the performance implications of using either exn keep history
> or using profile call?  I notice that it takes longer to compile and
> generates more code (not surprising) so there is some cost.

Using "-const 'Exn.keepHistory true'" implies "-profile call".  (Indeed, 
you can't use any other profiling with exception history.)

As with all profiling, the front-end inserts a bunch of profiling 
statements that records when control enters and leaves user level 
functions.  The middle-end optimizers do their best to treat these 
profiling statements as no-ops, but there are almost certainly some 
optimizations that get missed.

Obviously, getting the current call stack takes time proportional to the 
depth of the current call stack.  With "-const 'Exn.keepHistory true'" 
the call stack is taken at every "raise exn" expression in the program, 
whether or not the history of that particular exception is ever actually 
taken.  So, if you use exceptions for control-flow, you pay a penalty 
for each dynamic raise, regardless of how that raised exception is 
handled.  If you aren't using "-const 'Exn.keepHistory true'", but are 
using "-profile call", then you'll only pay the cost of the current 
stack depth at the times that you explicitly call MLton.CallStack.current.

If you see an unacceptable slow-down with "-profile call", then it 
suggests a missed optimization in the presence of profiling statements, 
and we'd like to see the program that demonstrates the slowdown, so that 
we can fix the optimization.




More information about the MLton-user mailing list