C++ vs. D memory management performance (Was: Faster Virtual Method Dispatch)
Sean Kelly
sean at f4.ca
Thu Apr 27 17:09:28 PDT 2006
Craig Black wrote:
>> Surprisingly, the slice code does substantially better than both the other
>> C++ versions and the D code. Perhaps this evening I'll re-run the C++
>> tests under Visual Studio to give the hash table a test drive.
>
> Wow! It's over twice as fast! How difficult would it be to use the same
> approach for wordcount in D by bypassing the GC?
The C++ slice code should mirror what is already happening in D--as far
as I know, the D code should allocate no memory at all for strings, only
for the AA. I suspect the problem may be GC scans of the rather large
(4 megabyte) data area where the book contents are stored. If the D
code were modified to allocate this memory via malloc instead of new,
the D program may speed up substantially. I'll see about dropping the
C++ file code into the D app this evening.
> So what do you think we should do about GC to make D faster? Do you favor
> making GC optional or writing a more optimized, compacting GC? I personally
> think that even optimized GC won't come close to code that has been
> optimized with manual memory management.
I'm not sure either approach could be said to be "better" than the other
insofar as performance is concerned as it really comes down to
application design. I'll admit that, until D, I'd always dismissed
garbage collection for one reason or another. But after using D for a
while I suddenly realized how much time and code I used to invest in
managing data ownership issues. I won't go so far as to say that data
ownership is not important, but being freed from the yoke of smart
pointer code and such I've found both that I'm more productive and that
the result is more elegant than its C++ equivalent. My only remaining
issue with GC is that it makes it too easy to ignore what's actually
going on at a low level. This probably isn't an issue for experienced
programmers who can't help but think about these things, but in I still
feel that learning programmers should be forced to deal with this stuff
simply so they're aware of it.
Sean
More information about the Digitalmars-d
mailing list