List of Phobos functions that allocate memory?

Marco Leise Marco.Leise at gmx.de
Sat Feb 8 23:03:34 PST 2014


Am Sat, 08 Feb 2014 14:01:12 -0800
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 2/7/2014 8:40 AM, Dmitry Olshansky wrote:
> > Meh. If exceptions are such a liability we'd better make them (much) faster.
> 
> They can be made faster by slowing down non-exception code.
> 
> This has been debated at length in the C++ community, and the generally accepted 
> answer is that non-exception code performance is preferred and exception 
> performance is thrown under the bus in order to achieve it.
> 
> I think it's quite a reasonable conclusion.

Am Sat, 08 Feb 2014 21:31:53 -0800
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 2/8/2014 9:00 PM, Marco Leise wrote:
> > The reasons for slow exceptions in D could be the generation
> > of stack trace strings or the garbage collector instead of
> > inherent trade offs to keep the successful code path fast.
> 
> Sigh, once again,
> 
> 1. It is not the collector
>
> 2. I've implemented it both ways, I know what I'm talking about. You can see the 
> fast exception way in the Win32 code generation, and the slow way in the Linux 
> code generation.

Ok, I'm on Linux which should be inherently slower at
throwing exceptions as you say. So I've written a little test
and it shows two things:
1. You are right, about the collector. It is not the
bottleneck.
2. It doesn't have anything to do with trading speed for the
   successful code path either.

I called two functions recursively until a nesting depth of
1000. The first version allocates a new exception, the second
one reuses an existing exception. At the call site I caught
the exception. I did this 10_000 times in a loop.
[The code is attached.]

Even at this nesting depth the second version still
outperformed the first one by a factor of ~200(!) and all
the CPU time (>98%) was is spent somewhere in libc.

Using static exceptions (or similarly in C++: throwing
literal strings) is VERY fast in D already and I see no reason
to improve that at the moment.

So I repeat my point:

The reasons for slow exceptions in D could be the generation
of stack trace strings or anything else other than some
inherent trade offs to keep the successful code path fast.

-- 
Marco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.d
Type: text/x-dsrc
Size: 1124 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140209/8703c39a/attachment.d>


More information about the Digitalmars-d mailing list