Linked by Thom Holwerda on Thu 6th Sep 2012 21:32 UTC, submitted by MOS6510
Benchmarks "During the 4th Semester of my studies I wrote a small 3d spaceship deathmatch shooter with the D-Programming language. It was created within 3 Months time and allows multiple players to play deathmatch over local area network. All of the code was written with a garbage collector in mind and made wide usage of the D standard library phobos. After the project was finished I noticed how much time is spend every frame for garbage collection, so I decided to create a version of the game which does not use a GC, to improve performance."
Thread beginning with comment 534191
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[2]: GC is for scripting
by tanzam75 on Fri 7th Sep 2012 05:49 UTC in reply to "RE: GC is for scripting"
tanzam75
Member since:
2011-05-19

Well, for ephemeral objects, then generational GC will speed up both allocation *and* deallocation. If it dies during its first collection, then there is zero overhead from the garbage collector.

It's actually the objects that survive a collection that incur the GC overhead, as they must be copied into the older generation.

There's a puzzling statement in the blog post that suggests the student may not have fully internalized this very counterintuitive fact:

... if you write code with a GC in mind you often do not think about the consequences when allocating memory, because the GC will deal with it. This often leads to highly imperformant code ... Comparision of TypeInfo objects in druntime is done by building two strings and then comparing those two strings. This will always leak memory and do a lot of unneccesary allocations which are a performance bottleneck.


But with a generational GC, it should not leak memory, and it should also not perform that badly. The temp strings should be ephemeral, and should die with no overhead. In other words, this is precisely the scenario that should perform faster with a GC than without a GC.

No wonder he ran into performance problems (and memory leaks) when he took out the GC!

Reply Parent Score: 1

RE[3]: GC is for scripting
by l3v1 on Fri 7th Sep 2012 06:56 in reply to "RE[2]: GC is for scripting"
l3v1 Member since:
2005-07-06

No wonder he ran into performance problems (and memory leaks) when he took out the GC!


Right, since high performance and non-leaking code can only be achieved by using a GC. I'd probably need a run to Rekall for that sentence not to make my head explode.

Reply Parent Score: 4

RE[4]: GC is for scripting
by tanzam75 on Sat 8th Sep 2012 17:36 in reply to "RE[3]: GC is for scripting"
tanzam75 Member since:
2011-05-19

If so, then you're making your own head explode. Because I never wrote that.

I pointed out that the student was complaining about "precisely the scenario" that performs better under GC than without GC, and then said that "no wonder" he ran into problems when he took out the GC.

In other words, you will write your code differently if you have a GC, compared to if you do not have a GC. If you have a GC, you do not worry too much about short-lived objects, but worry a great deal about medium-lived objects. If you do not have a GC, then you do not worry too much about medium-lived objects, but must take care to avoid excessive overhead from constructing and destructing short-lived objects.

Since the student directly ported code that assumes a GC, it is not surprising that he ran into problems when he took out the GC. Indeed, by tailoring the code to the non-GC platform, he was able to eliminate the performance penalty.

It's puzzling how you make the leap from that to the straw man that "high performance and non-leaking code can only be achieved by using a GC."

Edited 2012-09-08 17:38 UTC

Reply Parent Score: 3