Skip to content

Commit 974a7f7

Browse files
gh-135385: do not reserve inline values for attributes stored in slots (#156656)
1 parent 99d382c commit 974a7f7

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Reduce the memory consumption of instances of classes which define
2+
``__slots__`` and also have a ``__dict__``. Space for the attributes stored
3+
in slots is no longer reserved in the inline values of every instance.

‎Objects/dictobject.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7305,6 +7305,11 @@ _PyDict_NewKeysForClass(PyHeapTypeObject *cls)
73057305
PyObject *key = PyTuple_GET_ITEM(attrs, i);
73067306
Py_hash_t hash;
73077307
if (PyUnicode_CheckExact(key) && (hash = unicode_get_hash(key)) != -1) {
7308+
/* An attribute stored in a slot never uses the dict. */
7309+
PyObject *descr = _PyType_Lookup((PyTypeObject *)cls, key);
7310+
if (descr != NULL && Py_IS_TYPE(descr, &PyMemberDescr_Type)) {
7311+
continue;
7312+
}
73087313
if (insert_split_key(keys, key, hash) == DKIX_EMPTY) {
73097314
break;
73107315
}

0 commit comments

Comments
 (0)