Garbage collection in D

Aelx aelxx at yandex.ru
Sat Jul 25 14:00:47 PDT 2009


Diwaker Gupta Wrote:

> I've just started to play around with D, and I'm hoping someone can clarify this. I wrote a very simple program that just allocates lots of objects, in order to benchmark the garbage collector in D. For comparison, I wrote the programs in C++, Java and D:
> C++: http://gist.github.com/122708
> Java: http://gist.github.com/122709
> D: http://gist.github.com/121790
> 
> With an iteration count of 99999999, I get the following numbers:
> JAVA:
> 0:01.60 elapsed, 1.25 user, 0.28 system
> C++:
> 0:04.99 elapsed, 4.97 user, 0.00 system
> D:
> 0:25.28 elapsed, 25.22 user, 0.00 system
> 
> As you can see, D is abysmally slow compared to C++ and Java. This is using the GNU gdc compiler. I'm hoping the community can give me some insight on what is going on.
> 
> Thanks,
> Diwaker

Hi.
Inspired by this idea I changed somehow rules to make it more complicated task. So they are:
1. every "AllocationItem" has references to three other items. 
2. generate "n_items" in static array "items" of type "AllocationItem"
with "value" field set to "0"
3. make random connections between all this items by their reference fields
4. iterate "n_iters" times with the following agorithm 
 a) create new "AllocationArray" with "value" set to "1"
 b) replace random item from the array "items" with this new item
 c) add connections to this item
 d) remove (variant 1) or change (variant 2) three random connections
 e) now if some object isn't referenced by others it should be removed (GC collected).
5. calculate count  of old items (with "value" set to 0) and new ones
Here are my programs in D and Java. There is no C++ variant, sorry.
In D I used modified for D2 Bill Baxter's weak reference module: http://www.dsource.org/projects/scrapple/browser/trunk/weakref

now results:
1) it works strange, as from time to time it gives different results in D2 (approx. 1 in 10) and it's no by RNG.
2) java's version is awfully slow (may be because it's my second java app, first was 8 jears ago). now I hate java even more.
3) java and D give different results. It's all strange. Maybe I made something wrong.



More information about the Digitalmars-d-learn mailing list