mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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)
This commit is contained in:
parent
e5b78563b6
commit
f8387af262
11 changed files with 401 additions and 2 deletions
|
@ -285,6 +285,17 @@ extern PyGC_Head *_PyGC_generation0;
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue