Jump to page: 1 2 3
Thread overview
Garbage collection in D
Jun 03, 2009
Diwaker Gupta
Jun 03, 2009
Tim Matthews
Jun 03, 2009
BCS
Jun 03, 2009
bearophile
Jun 03, 2009
bearophile
Jun 03, 2009
Robert Fraser
Jun 03, 2009
bearophile
Jun 04, 2009
Sam Hu
Jun 04, 2009
Robert Fraser
Jun 04, 2009
bearophile
Jun 04, 2009
Frits van Bommel
Jun 04, 2009
bearophile
Jun 04, 2009
Frits van Bommel
Jun 04, 2009
Robert Fraser
Jun 10, 2009
bearophile
Jun 04, 2009
Robert Fraser
Jun 04, 2009
bearophile
Jun 04, 2009
Rainer Deyke
Jun 04, 2009
Sam Hu
Jun 03, 2009
Robert Clipsham
Jun 03, 2009
Robert Clipsham
Jun 03, 2009
Rainer Deyke
Jun 03, 2009
TSalm
Jul 25, 2009
Aelx
June 03, 2009
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
June 03, 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

Can someone try dmd and ldc as gdc is dying (if not already dead). Also code in the iterations and take out the command line reading and printing so to make it accurate.
June 03, 2009
On Tue, Jun 2, 2009 at 8:40 PM, Diwaker Gupta <diwaker@floatingsun.net> 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.

D's GC is not nearly as well-developed as that of Java's, and its performance is not that stellar.  Sorry, but you are not the first to discover this by any stretch of the imagination.  (On a side note, I have a feeling you and bearophile will get on famously.)

Also, benchmarking a GC against manual memory management doesn't do much for you.  It's apples and oranges.  Though it is funny to see how badly Java beats C++ there.
June 03, 2009
Hello Jarrett,

> On Tue, Jun 2, 2009 at 8:40 PM, Diwaker Gupta
> <diwaker@floatingsun.net> 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.
>> 
> D's GC is not nearly as well-developed as that of Java's, and its
> performance is not that stellar.  Sorry, but you are not the first to
> discover this by any stretch of the imagination.  (On a side note, I
> have a feeling you and bearophile will get on famously.)
> 
> Also, benchmarking a GC against manual memory management doesn't do
> much for you.  It's apples and oranges.  Though it is funny to see how
> badly Java beats C++ there.
> 

Java may be able to tell that the allocation never needs to be kept and is just reusing the same space on the stack. Heck it might even not be doing that as you can tell that the class only ever holds the same value as i so it might just be skipping the new all together.


June 03, 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

After porting the D version to tango:

D: 6.282s (ldmd -O5 -inline -release -L-s -singleobj gctest.d)
C++: 4.435s (g++ -O5 gctest.d)

This is on a C2D 2.2Ghz, 2GB RAM, Linux x86-64. I don't have java installed, so can't test that. Maybe if you're planning to use the GC a lot you should consider using tango?
June 03, 2009
Le Wed, 03 Jun 2009 02:40:11 +0200, Diwaker Gupta <diwaker@floatingsun.net> a écrit:

> 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
>

I think the line 14 in the D source is useless.
On my linux system :

D with line 14 removed :
----------------------
tsalm@fgabriel:~/dev/DBenchmark$ time ./Benchmark allocations 99999999
787459713

real    0m28.779s
user    0m28.778s
sys     0m0.004s

C++:
---
tsalm@fgabriel:~/dev/DBenchmark$ time ./a.out allocations 99999999
Ran 99999999 allocations of RunAllocations. Final value: 787459713

real    0m16.406s
user    0m16.405s
sys     0m0.004s

Java :
-----
tsalm@fgabriel:~/dev/DBenchmark$ time java Benchmark allocations 99999999
Ran 99999999 allocations of RunAllocations. Final value: 787459713

real    0m6.679s
user    0m6.408s
sys     0m0.248s

But with the use of "scope" keyword at line 13 of the D source :
tsalm@fgabriel:~/dev/DBenchmark$ time ./Benchmark allocations 99999999
787459713

real    0m10.752s
user    0m10.753s
sys     0m0.000s
June 03, 2009
Robert Clipsham wrote:
> After porting the D version to tango:
> 
> D: 6.282s (ldmd -O5 -inline -release -L-s -singleobj gctest.d)
> C++: 4.435s (g++ -O5 gctest.d)
> 
> This is on a C2D 2.2Ghz, 2GB RAM, Linux x86-64. I don't have java installed, so can't test that. Maybe if you're planning to use the GC a lot you should consider using tango?

After reading TSalm's post, I reran the D version with the scope keyword at line 16:

D (with scope): 1.098s
D: 6.282s
C++: 4.435s

It seems by using scope and tango you can easily compete with C++.
June 03, 2009
Jarrett Billingsley:
> (On a side note, I have a feeling you and bearophile will get on famously.)<

I have found a new friend ;-)

Some timings, usual settings, Core2 2 GHz:

Timings, N=100_000_000, Windows, seconds:
  D 1:  40.20 DMD
  D 2:  21.83 DMD
  D 2:  18.80 DMD, struct + scope
  C++:  18.06
  D 1:   8.47 DMD
  D 2:   7.41 DMD + scope
  Java   1.78 -server
  Java:  1.44

Timings, N=100_000_000, Pubuntu, seconds:
  D 1:  25.7  LDC
  C++:   6.87
  D 1:   2.67 LDC + scope
  Java:  1.49

Poor LDC :-)

Bye,
bearophile
June 03, 2009
I have tried the new JavaVM on Win, that optionally performs escape analysis, and the results are nice:

Timings, N=100_000_000, Windows, seconds:
  D 1:  40.20 DMD
  D 2:  21.83 DMD
  D 2:  18.80 DMD, struct + scope
  C++:  18.06
  D 1:   8.47 DMD
  D 2:   7.41 DMD + scope
  Java:  1.84 V.1.6.0_14, -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
  Java   1.78 -server
  Java:  1.44
  Java:  1.38 V.1.6.0_14
  Java:  0.28 V.1.6.0_14, -server -XX:+DoEscapeAnalysis

Timings, N=100_000_000, Pubuntu, seconds:
  D 1:  25.7  LDC
  C++:   6.87
  D 1:   2.67 LDC + scope
  Java:  1.49

Bye,
bearophile
June 03, 2009
Robert Clipsham wrote:
> After reading TSalm's post, I reran the D version with the scope keyword at line 16:
> 
> D (with scope): 1.098s
> D: 6.282s
> C++: 4.435s
> 
> It seems by using scope and tango you can easily compete with C++.

'scope' eliminates dynamic memory allocation.  At this point you're not measuring the speed of the garbage collector at all.  For a fair comparison, you should also eliminate the useless dynamic memory allocation from the C++ version.


-- 
Rainer Deyke - rainerd@eldwood.com
« First   ‹ Prev
1 2 3