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 534397
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[6]: GC is for scripting
by sakeniwefu on Sun 9th Sep 2012 02:56 UTC in reply to "RE[5]: GC is for scripting"
sakeniwefu
Member since:
2008-02-26


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

I still don't think it's safe to assume these generalisations are accurate without benchmarking them in an application.


Benchmark, benchmark, and when you've established that there isn't any possible bottleneck other than memory allocation, then it still isn't the memory allocation system.

Some time ago, I designed and implemented an abstraction layer for an embedded OS and when the app it was serving was reported as being too slow by the customers my system allocator wrapper was singled out as the problem by the "profiler".

This was in a world of custom prematurely optimized everything. So my decision to keep it simple was met with little sympathy.

So, I rewrote it with a custom memory management algorithm to the point allocation and release were barely slower on average than a void (library) function call.

Guess what? It still was the bottleneck.

Some good old printf profiling revealed that the OOP client application was hitting it like crazy.

Classic allocation, Reference Counting, Garbage Collection, it wouldn't have made a difference.

The problem I see in all of GC, RAII(for system memory) or ARC is that they encourage the everything is an object mentality. And that mentality generally turns into programs that hit the allocator way too much.

Reply Parent Score: 2

RE[7]: GC is for scripting
by Alfman on Sun 9th Sep 2012 19:38 in reply to "RE[6]: GC is for scripting"
Alfman Member since:
2011-01-28

sakeniwefu,

"Benchmark, benchmark, and when you've established that there isn't any possible bottleneck other than memory allocation, then it still isn't the memory allocation system."

Well, GCC's allocator is not very good especially on SMP systems where it can be a bottleneck. So it might make sense to tinker with new allocators but I wouldn't want to imply that allocation is typically a bottleneck in most applications.


"So, I rewrote it with a custom memory management algorithm to the point allocation and release were barely slower on average than a void (library) function call."

I'm curious about the implementation, I've written my own too where objects were pooled in thread local storage and therefore incurred no overhead on SMP until the global allocator was hit to replenish the pools.


"Guess what? It still was the bottleneck. Some good old printf profiling revealed that the OOP client application was hitting it like crazy."

This should have been uncovered much earlier. Didn't the profiler give function counts?



"The problem I see in all of GC, RAII(for system memory) or ARC is that they encourage the everything is an object mentality. And that mentality generally turns into programs that hit the allocator way too much."

Absolutely, one of the easiest ways to improve low level performance is by reducing the number of objects we need to accomplish our tasks. If a process always allocates A+B+C, then those could be combined into one monolith object instead, reducing object overhead by a factor of 3 for both GC or non-GC languages. However many people are going to be on edge about where to draw the line between OOP purity and overhead. Even though ideally one might want to manipulate pixels as objects, the OOP paradigm just breaks down due to the inefficiency of having so many numerous objects. Some day we could have a language with virtual objects which don't exist in memory, but allow us to manipulate the pixels as if they were real objects.

Reply Parent Score: 2