Dot Net Perls

Garbage Collection Performance Research

by Sam Allen

Problem

Is garbage collection slow, or is that a myth? Here we discuss the plusses and minuses of garbage collection and its performance statistics. It is interesting to think about when it is better and when it is worse than reference-counting or regular malloc. We want to respond to an interesting post at Lambda the Ultimate (linked below) about this topic.

Solution

Lambda the Ultimate is a site about programming languages and many of the articles deal with more abstract or theoretical concepts than just tutorials. There is an interesting post about the performance of garbage collection in computer languages there. We will look at the summary of the research paper and see what we can learn from it.

What was tested?

The researchers in the study tested Java programs that were written originally with the JVM, which uses garbage collection. The twist here is that they ran the Java apps with a regular memory allocator. This is the "novel experimental methodology". Sometimes it is possible for developers to "swap" memory allocators, and this is what they did.

What were the results?

As .NET developers, we have an interest in garbage collection being fast. However, this article reveals an interesting factor: because garbage collection (in the mark and sweep) visits so many different pages in memory, it has bad locality of reference, and virtual memory, which is much slower, suffers tremendously.

If your program usesThen garbage collection is
Mainly regular memory50% larger in memory
5-10% slower
Virtual memory10-15 times slower

Is this important?

Yes and no. I know many programs that would not really be affected by a substantial slowdown. Additionally, as computers move to 64-bit, we will become less reliant on virtual memory, and have more regular memory. Because of this, it seems to me that these problems will become less pronounced in the future.

Does it matter?

I don't feel that the difference between garbage collected programs and reference-counted ones is significant in modern programming most of the time. In fact, projects such as Mozilla Firefox seem to be moving to more garbage collection. This will improve the serious memory concerns many browsers have. Garbage collection can provide a more robust framework that is more resistant to "bloat".

Where do I read more?

Wikipedia, as usual, has good resources on garbage collection. At Wikipedia, read about garbage collection and virtual memory. Additionally, Lambda the Ultimate is an interesting site that deals with many parts of advanced programming. Look for this article at Lambda to see the reference in this post.

Conclusion

Garbage collection's merits have been debated by computer scientists for many years. .NET and Java has shown that practical applications can thrive on GC. However, high-performance or sometimes scientific programs still often prefer other approaches. As computers become more powerful, I feel that garbage collection will become an even more compelling option.

Dot Net Perls
About
Sitemap
Source code
RSS
Language Features
Struct Examples and Tricks
Run Commands With Process.Start
Singleton Pattern vs. Static Class
NGEN Installer Class
Enum Tips and Examples
Recent
Pi
NGEN Installer Class
List Element Equality
DateTime Tips and Tricks
Remove HTML Tags From String
© 2008 Sam Allen. All rights reserved.