A couple garbage collector questions

Dan Sugalski dan at tuatha.sidhe.org
Tue Apr 3 22:26:35 EDT 2001


Neelakantan Krishnaswami <neelk at alum.mit.edu> wrote:
> On Tue, 03 Apr 2001 16:02:51 +1200, Greg Ewing <greg at cosc.canterbury.ac.nz>
> wrote:
>>Kragen Sitaker wrote:
>>> 
>>> Reference-counting exacts very heavy performance costs, no matter what
>>> you back it up with.
>>
>> Something nobody has mentioned yet is that RC is cache-friendly,
>> whereas pure M&S is quite cache-hostile. This is important now that
>> most machine architectures are heavily reliant on cacheing for good
>> performance, and I believe that it is one of the main reasons for
>> retaining RC alongside the new GC mechanisms.

> Naive question: wouldn't adding a word (for the RC) to every object
> make locality worse? I'd appreciate an explanation of why it improves
> locality -- this seems highly nonintuitive to me. 

Generally you're accessing the reference count at the same time you're
accessig the rest of the object, so you've probably already got the RC in
either your L1 or L2 cache, courtesy of largish cache lines.

While a M&S seems cache hostile, it's actually not that bad, since it'll
generally access an object less often than refcounting will. Depending on
how transient your objects are you may get another win, as you may find a
large portion of your objects die before you do a GC pass, thus not
touching them at all, as M&S goes for active data only. Not having extra
space for a RC also makes objects smaller and thus take fewer transfers
from memory.

There are also a number of other versions of the traditional M&S that are
more responsive and more cache friendly too. (Generational garbage
collectors are rather nice)

				Dan



More information about the Python-list mailing list