From: Roger Pack Date: 2008-07-20T09:43:50+09:00 Subject: Re: JRuby performance questions answered Rick Denatale wrote: > Roger, you REALLY need to read the literature on GC which has been > accumulating for the past 50 years. > > Reference counting is pretty much an obsolete approach to GC. It was > probably the first approach taken for lisp back in the 1950s. Other > language implementations usually started with reference counting (e.g. > the first Smalltalk). > > It's main advantage is that it's easy to understand. On the other hand > it incurs a large overhead since counts need to be > incremented/decremented on every assignment. It can't detect circular > lists of dead objects. In early Smalltalk programs when reference > counting was used, you needed to explicitly nil out references to > break such chains. There's also the issue of the overhead for storing > the reference count, and how many bits to allocate. Most reference > counting implementations punt when the reference count overflows, they > treat a 'full' count as an infinite count and no longer decrement it, > leading to more uncollectable objects. > > Mark and sweep, such as is used in the Ruby 1.8 implementation quickly > replaced reference counting as the simplest GC considered for real > use. This is somewhat confusing for me, because it seems that using a mark and sweep generational style GC slows down Ruby, as per Matz's observations: http://www.ruby-forum.com/topic/123747 On my own I tried integrating Boehm's GC as a drop in replacement and it seemed to cause a serious slowdown [possibly because I didn't integrate it right :P ] Also macruby reports that their runtime is slightly slower, I'll make a big assumption--because it uses a conservative GC so it can't allocate as cheaply [however their garbage collection is faster, and runs in a different thread so doesn't cause a program halt--so not all bad there] Performance-wise, Python uses reference counting and seems to have 'acceptable' performance. They avoid the circular problems by running a full mark and sweep every so often. I suppose I'm just naive, but it doesn't seem clear to me which is the 'best' GC style, from the above observations. There appears to be no clear answer. Cheers! -R > Which particular GC approach is best for Ruby is subject to some study. -- Posted via http://www.ruby-forum.com/.