开发者

What advantage is there to only collecting large-object-heap objects with Generation 2?

I understand that generational garbage collection improves performance, since

  1. Any object will have to be moved at most twice in non-Gen2 collections, and Gen2 collections are rare.
  2. If the system is performing a Gen0 collection and an object (Gen1 or Gen2) hasn't been written since the last Gen0 collection, the system won't have to scan that object to tag any references therein (since they'll all be Gen1 or Gen2). Likewise if the system is performing a Gen1 collection, it can ignore any object not written since the last Gen1 collection. Since most of the work of garbage-collection is scanning objects, reducing the scanning time is a big win.

I'm curious, though, what performance advantage there could be to omitting large objects from Gen1 garbage collection? Large objects aren't relocated even when they're scanned by the garbage collector, and I would expect that Gen1 collections will still have to scan their contents unless or until two consecutive Gen1 collections occur without intervening object writes.

Is there some performance advan开发者_运维技巧tage I'm not seeing?


I'm curious, though, what performance advantage there could be to omitting large objects from Gen1 garbage collection?

There are two things -

First, large objects (large enough to be on the LOH) tend to have longer lifetimes. Short-lived large objects are rare, and in the cases where that's needed, you can typically reuse them. By not scanning, you're effectively avoiding scans that, nearly always, will result in keeping the objects anyways. This tends to give you a win in perf.

Also, in order to effectively treat objects in Gen1, and get many of the advantages provided by having a Gen1, they'd need to be able to compact. A large advantage of the generational collector is you're compacting the newest allocations, which tends to help keep the memory pressure lower as fragmentation tends to be better behaved. Large objects in Gen1 would cause performance or memory issues, as they'd either require compacting (right now, large objects are not compacted, since it's expensive to "move" them) or they'd cause extra fragmentation to creep up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜