Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does garbage collection affect performance?

I am just reading about the performance of several programming languages, and I noticed that garbage collection gets mentioned fairly often. Does garbage collection affect the performance of a language at all? If yes, how?

like image 707
user3289157 Avatar asked Aug 14 '14 16:08

user3289157


1 Answers

One thing to keep in mind here is that a language without garbage collection still has to allocate and free objects. Garbage collection allows the "free" part of the operation to happen in batches, and at times when the application is otherwise relatively idle. In other words, a highly-efficient garbage collector has the potential to be faster (not that we're quite that far yet, but they are improving all the time).

The trick is that when garbage collections do occur, the collector still has to spend resources doing the analysis of what is reachable, and what isn't, or what has a reference count > 0, and what doesn't. That is a performance penalty.

The result is that, for most garbage collected platforms, the collector is one factor to consider when evaluating performance. The net effect of the garbage collector may be minimal — or even a net positive! — over the life of an application session, but there can short-lived periods where there is significant negative impact.

like image 86
Joel Coehoorn Avatar answered Oct 17 '22 02:10

Joel Coehoorn