[Python-ideas] Save memory when forking with *really* immutable objects

Jim Jewett jimjjewett at gmail.com
Wed Mar 14 23:07:14 CET 2012


On Mon, Mar 12, 2012 at 8:10 PM, Larry Hastings <larry at hastings.org> wrote:

> The obvious first step: add a magical reference count number that never
> changes, called Py_REF_ETERNAL.

If you have a magic number, you need to check before doing the update;
at some point in the distant past, that was considered too expensive
because it is done so often.

But once you do pay the cost of a more expensive refcount update, this
isn't the only optimization available.  For example, the incref/decref
can be delayed or batched up, which can help with remote objects or
incremental garbage collection.  Gating reference acquisition may also
be re-purposed to serve as thread-locking, or to more efficiently
support Software Transactional Memory.

>  Martin suggests that this wouldn't help unless we could concentrate the
> Py_REF_ETERNAL objects in their own memory pools in the small block
> allocator.

Right; it makes sense to have the incref/decref function be per-arena,
or at least per page or some such.

-jJ



More information about the Python-ideas mailing list