Performance of exception handling

Denis Koroskin 2korden at gmail.com
Tue Apr 26 09:29:49 PDT 2011


On Tue, 26 Apr 2011 20:14:05 +0400, Sean Kelly <sean at invisibleduck.org>  
wrote:

> Right now, traces are generated on throw. It should be possible to  
> generate them on catch instead. The performance would be the same either  
> way however. It would be nice to generate them lazily but I don't think  
> that's possible.
>
> Sent from my iPhone
>

Interesting enough, it is already done lazily (in toString(), which I  
believe should also cache result when it's called first time), but it can  
be improved a bit. Here is what it currently does:


class DefaultTraceInfo : Throwable.TraceInfo
{
     this()
     {
         static enum MAXFRAMES = 128;
         void*[MAXFRAMES]  callstack;

         numframes = backtrace( callstack, MAXFRAMES );			// 1
         framelist = backtrace_symbols( callstack, numframes );	// 2
     }

     // ...
}

While the first line is definitely required (otherwise stack information  
gets lost), I believe the second one is not and can be moved to opApply  
(or somewhere else).


More information about the Digitalmars-d mailing list