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."
Permalink for comment 534191
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"
Member since:

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