托管环境日益流行, 作为托管中重要环节的 GC, 对性能有比较大的影响, 所以对 GC 机制的一定了解, 还是有必要的.
原文讨论了他们公司实现 Pauseless GC 的思路, 在 reddit 的讨论中也有一些很精彩的评论, 在此摘抄部分.
rayiner@reddit
"There is no such thing as "pauseless" memory management. All memory management systems have pauses, the real question is what is the distribution, length, and character of the pauses on various allocation loans?
malloc() has relatively long pauses on allocation and symmetric pauses on frees. However, generally the pauses are of predictable length (though by no means bounded, at all, because you can hit pathological cases scanning free-lists).
A copying generational GC has a very short pause on allocating objects (however long it takes to bump a pointer) and no pause on freeing objects (the tracer never visits dead objects), but potentially long pauses when objects stay alive between collections.
There are a lot of loads where all the pauses involved in malloc() add up to more than what you'll see with a generational GC. On most functional code where there is a lot of temporary state but very little long-term state, a GC will do very little work copying live data at each collection, while a malloc() implementation will have to muck with an increasingly more fragmented free-list for each malloc()/free(). On the flip side, on imperative code where you have a ton of long-lived state, a GC will do a lot of work copying live objects on each collection, while a malloc() implementation will do nothing if objects are just sitting around."