Skip to content

Commit 63d9b90

Browse files
committed
Fast dealloc of immortal tuples
1 parent 2ff5eb8 commit 63d9b90

92 files changed

Lines changed: 1060 additions & 90 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Include/cpython/tupleobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ typedef struct {
66
PyObject_VAR_HEAD
77
/* Cached hash. Initially set to -1. */
88
Py_hash_t ob_hash;
9+
int contains_mortal;
910
/* ob_item contains space for 'ob_size' elements.
1011
Items must normally not be NULL, except during construction when
1112
the tuple is not yet visible outside the function that builds it. */
@@ -35,6 +36,7 @@ PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
3536
assert(0 <= index);
3637
assert(index < Py_SIZE(tuple));
3738
tuple->ob_item[index] = value;
39+
tuple->contains_mortal |= !_Py_IsImmortal(value);
3840
}
3941
#define PyTuple_SET_ITEM(op, index, value) \
4042
PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))

Include/internal/pycore_runtime_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern PyTypeObject _PyExc_MemoryError;
108108
.tuple_empty = { \
109109
.ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0), \
110110
.ob_hash = _PyTuple_HASH_EMPTY, \
111+
.contains_mortal = 0, \
111112
}, \
112113
.hamt_bitmap_node_empty = { \
113114
.ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0), \

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef struct {
4444
static inline void
4545
_PyTuple_Recycle(PyObject *op)
4646
{
47+
((PyTupleObject *)op)->contains_mortal = 0;
4748
_PyTuple_RESET_HASH_CACHE(op);
4849
if (!_PyObject_GC_IS_TRACKED(op)) {
4950
_PyObject_GC_TRACK(op);

Modules/_ctypes/clinic/cfield.c.h

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/_iomodule.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/bufferedio.c.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/bytesio.c.h

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/fileio.c.h

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/stringio.c.h

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/textio.c.h

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)