Index: Modules/gcmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v retrieving revision 2.41 diff -u -U1 -r2.41 gcmodule.c --- Modules/gcmodule.c 4 May 2002 05:35:20 -0000 2.41 +++ Modules/gcmodule.c 21 May 2002 15:48:54 -0000 @@ -168,2 +173,42 @@ +/* return true if a tuple does not contain any GC objects */ +static int +tuple_is_simple(PyObject *op) +{ + int i, n; + n = PyTuple_GET_SIZE(op); + for (i = 0; i < n; i++) { + PyObject *item = PyTuple_GET_ITEM(op, i); + if (item == NULL || PyObject_IS_GC(item)) + return 0; + } + return 1; +} + +/* Untrack simple objects that cannot create reference cycles. This + * helps reduces the size of the older generations. */ +static void +untrack_simple_objects(PyGC_Head *containers) +{ + PyObject *op; + PyGC_Head *next; + PyGC_Head *gc = containers->gc.gc_next; + int n = 0; + while (gc != containers) { + next = gc->gc.gc_next; + op = FROM_GC(gc); + if (PyTuple_CheckExact(op) && tuple_is_simple(op)) { + /* should be safe to ignore, untrack it */ + n += 1; + gc_list_remove(gc); + gc->gc.gc_next = NULL; + } + gc = next; + } +#if 0 + if (n > 0) + PySys_WriteStderr("gc: untracked %d simple tuples\n", n); +#endif +} + static int @@ -409,2 +453,8 @@ +#if 1 + /* an optimization to reduce the number of tracked objects */ + if (generation == 1) + untrack_simple_objects(young); +#endif + /* Using ob_refcnt and gc_refs, calculate which objects in the