[Fwd: A couple garbage collector questions]

Frank Mitchell frankm at bayarea.net
Sat Apr 21 17:15:43 EDT 2001


Jeff Petkau wrote:
>
> Daniel Berlin <dan at www.cgsoftware.com> wrote in message
> news:mailman.987747988.15494.python-list at python.org...
> >...
> > Cache locality isn't hurt, why the heck would you decref an object you
> > hadn't just used? Why the heck would you incref an object you weren't
> > about to use?
> >
> > Branch prediction isn't an issue here, you'd have the same problem in any
> > garbage collection schemes.
> >
> > So where is the huge performance cost i'm paying?
> > --Dan
>
> On some modern processors, reference counting could actually be
> faster than no memory management at all--the incref basically
> acts as a prefetch, for suitably sized and aligned objects.

OTOH, if the program *isn't* going to use the object right away, e.g. if
object A hands object B a referece to object C so that A can call C at a
later time, you're prefetching for no purpose.
 
BTW, there's an algorithm for one-bit reference counts that puts the bit
in the object pointer.  That is, if the pointer has the lowest-order bit
set, and you delete that reference, you know it's safe to delete the
memory it points to (assuming objects are aligned on even addresses).
There are some complications, of course, such as temporary references
that would "stick" the count permanently to more than two, requiring
either a second bit or an "ought to be two" cache.

> Of course that's just random speculation, but isn't random
> speculation is what memory management arguments are all about?

The ones that are a subset of optimization arguments, yes.

To haul the thread back toward the original topic, the real argument
against refcounting is its inability to collect cycles without
programmer intervention.  Some applications and languages are guaranteed
not to create cycles ... but an interpreter for a general
object-oriented language isn't one of them

-- 
Frank Mitchell (frankm at bayarea.net)

Ridiculous Lucky Captain Rabbit King!  Lucky Captain Rabbit King
Nuggets are only for the youth!
-- Powerpuff Girls, "Jewel of the Aisle"



More information about the Python-list mailing list