Thoughts about D

Adam D. Ruppe destructionator at gmail.com
Thu Nov 30 16:48:10 UTC 2017


On Thursday, 30 November 2017 at 16:12:04 UTC, H. S. Teoh wrote:
> Can you elaborate?

As I understand it, DWARF exception handling even on the 
non-exceptional case, is a bit more expensive than our old way. 
Not hugely expensive but for dmd where we count milliseconds it 
might add up.

> Which brings us to the implementation of assert() itself. What 
> about it makes it so big? I suspect most of the bloat comes 
> from throwing AssertError, which pulls in the stack-unwinding 
> code, which, if my memory is still up to date, suffers from 
> performance issues where it tries to construct the stacktrace 
> regardless of whether or not the catch block actually wants the 
> stacktrace.

That's false, I changed that many years ago myself, unless the 
DWARF change involved that too, but I don't think so.

What happens is the exception constructor walks the stack and 
copies the addresses to a local, static buffer. This is very fast 
- just walking a linked list and copying some void* into a 
void*[64] or whatever - and little code.

The expensive part of formatting it to a string, actually looking 
up the debug info, parsing out the addresses, etc., is done 
lazily when it is printed, which occurs only on demand or right 
before the program terminates.




More information about the Digitalmars-d mailing list