Mercurial > cpython-lru_cache-weakref
diff Include/objimpl.h @ 52291:94bd0666ffa7
Merged revisions 70546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70546 | antoine.pitrou | 2009-03-23 19:41:45 +0100 (lun., 23 mars 2009) | 9 lines
Issue #4688: Add a heuristic so that tuples and dicts containing only
untrackable objects are not tracked by the garbage collector. This can
reduce the size of collections and therefore the garbage collection overhead
on long-running programs, depending on their particular use of datatypes.
(trivia: this makes the "binary_trees" benchmark from the Computer Language
Shootout 40% faster)
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Mon, 23 Mar 2009 18:52:06 +0000 |
| parents | 86a2679dca46 |
| children | f197407bdba2 b6aff7a59803 |
line wrap: on
line diff
--- a/Include/objimpl.h Mon Mar 23 18:44:57 2009 +0000 +++ b/Include/objimpl.h Mon Mar 23 18:52:06 2009 +0000 @@ -282,6 +282,17 @@ g->gc.gc_next = NULL; \ } while (0); +/* True if the object is currently tracked by the GC. */ +#define _PyObject_GC_IS_TRACKED(o) \ + ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED) + +/* True if the object may be tracked by the GC in the future, or already is. + This can be useful to implement some optimizations. */ +#define _PyObject_GC_MAY_BE_TRACKED(obj) \ + (PyObject_IS_GC(obj) && \ + (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj))) + + PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t); PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *); PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
