[Python-3000] Delayed reference counting idea

Josiah Carlson jcarlson at uci.edu
Tue Sep 19 18:23:01 CEST 2006

"Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> wrote:
> Brian Quinlan <brian at sweetapp.com> writes:
> >> Reference counting is inefficient, doesn't by itself handle cycles,
> >> and is impractical to combine with threads which run in parallel. The
> >> general consensus of modern language implementations is that a tracing
> >> GC is the future.
> >
> > How is reference counting inefficient?
> It involves operations every time an object is merely passed around,
> as references to the object are created or destroyed.

Redefine the INC/DECREF macros to assign something like 2**30 as the
reference count in INCREF, and make DECREF do nothing.  A write of a
constant should be measurably faster than an increment.  Run some
relatively small test program (be concerned about memory!), and compare
the results to see if there is a substantial difference in performance.

> It doesn't move objects in memory, and thus free memory is fragmented.
> Memory allocation can't just chop from from a single area of free memory.
> It can't allocate several objects with the cost of one allocation either.

It can certainly allocate several objects with the cost of one
allocation, but it can't *deallocate* those objects individually.  See
the various freelists for examples where this is used successfully in
Python now.

 - Josiah

More information about the Python-3000 mailing list