diff options
author | Mark Shannon <mark@hotpy.org> | 2021-10-13 13:19:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 13:19:34 (GMT) |
commit | a8b9350964f43cb648c98c179c8037fbf3ff8a7d (patch) | |
tree | 13a539432c9d48ac278d34d040f17a7a12eac771 /Include | |
parent | 97308dfcdc0696e0b116c37386e2ff4d72e6c3f4 (diff) | |
download | cpython-a8b9350964f43cb648c98c179c8037fbf3ff8a7d.zip cpython-a8b9350964f43cb648c98c179c8037fbf3ff8a7d.tar.gz cpython-a8b9350964f43cb648c98c179c8037fbf3ff8a7d.tar.bz2 |
bpo-45340: Don't create object dictionaries unless actually needed (GH-28802)
* Never change types' cached keys. It could invalidate inline attribute objects.
* Lazily create object dictionaries.
* Update specialization of LOAD/STORE_ATTR.
* Don't update shared keys version for deletion of value.
* Update gdb support to handle instance values.
* Rename SPLIT_KEYS opcodes to INSTANCE_VALUE.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/object.h | 1 | ||||
-rw-r--r-- | Include/internal/pycore_dict.h | 2 | ||||
-rw-r--r-- | Include/internal/pycore_object.h | 10 | ||||
-rw-r--r-- | Include/object.h | 1 | ||||
-rw-r--r-- | Include/opcode.h | 21 |
5 files changed, 25 insertions, 10 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 5ae6f36..849d5aa 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -270,6 +270,7 @@ struct _typeobject { destructor tp_finalize; vectorcallfunc tp_vectorcall; + Py_ssize_t tp_inline_values_offset; }; /* The *real* layout of a type object when allocated on the heap */ diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h index d37ef71..13cb7cc 100644 --- a/Include/internal/pycore_dict.h +++ b/Include/internal/pycore_dict.h @@ -101,6 +101,8 @@ extern uint64_t _pydict_global_version; #define DICT_NEXT_VERSION() (++_pydict_global_version) +PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values); + #ifdef __cplusplus } #endif diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 82dddf1..3c126aa 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -181,6 +181,16 @@ extern int _Py_CheckSlotResult( extern PyObject* _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems); extern int _PyObject_InitializeDict(PyObject *obj); +extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values, + PyObject *name, PyObject *value); +PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values, + PyObject *name); +PyDictValues ** _PyObject_ValuesPointer(PyObject *); +PyObject ** _PyObject_DictPointer(PyObject *); +int _PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg); +void _PyObject_ClearInstanceAttributes(PyObject *self); +void _PyObject_FreeInstanceAttributes(PyObject *self); +int _PyObject_IsInstanceDictEmpty(PyObject *); #ifdef __cplusplus } diff --git a/Include/object.h b/Include/object.h index c3062cb..7f050b8 100644 --- a/Include/object.h +++ b/Include/object.h @@ -333,6 +333,7 @@ given type object has a specified feature. */ #ifndef Py_LIMITED_API + /* Set if instances of the type object are treated as sequences for pattern matching */ #define Py_TPFLAGS_SEQUENCE (1 << 5) /* Set if instances of the type object are treated as mappings for pattern matching */ diff --git a/Include/opcode.h b/Include/opcode.h index 8817a4d..15f7226 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -147,7 +147,7 @@ extern "C" { #define BINARY_SUBSCR_DICT 39 #define JUMP_ABSOLUTE_QUICK 40 #define LOAD_ATTR_ADAPTIVE 41 -#define LOAD_ATTR_SPLIT_KEYS 42 +#define LOAD_ATTR_INSTANCE_VALUE 42 #define LOAD_ATTR_WITH_HINT 43 #define LOAD_ATTR_SLOT 44 #define LOAD_ATTR_MODULE 45 @@ -158,15 +158,16 @@ extern "C" { #define LOAD_METHOD_CACHED 80 #define LOAD_METHOD_CLASS 81 #define LOAD_METHOD_MODULE 87 -#define STORE_ATTR_ADAPTIVE 88 -#define STORE_ATTR_SPLIT_KEYS 120 -#define STORE_ATTR_SLOT 122 -#define STORE_ATTR_WITH_HINT 123 -#define LOAD_FAST__LOAD_FAST 127 -#define STORE_FAST__LOAD_FAST 128 -#define LOAD_FAST__LOAD_CONST 134 -#define LOAD_CONST__LOAD_FAST 140 -#define STORE_FAST__STORE_FAST 143 +#define LOAD_METHOD_NO_DICT 88 +#define STORE_ATTR_ADAPTIVE 120 +#define STORE_ATTR_INSTANCE_VALUE 122 +#define STORE_ATTR_SLOT 123 +#define STORE_ATTR_WITH_HINT 127 +#define LOAD_FAST__LOAD_FAST 128 +#define STORE_FAST__LOAD_FAST 134 +#define LOAD_FAST__LOAD_CONST 140 +#define LOAD_CONST__LOAD_FAST 143 +#define STORE_FAST__STORE_FAST 149 #define DO_TRACING 255 #ifdef NEED_OPCODE_JUMP_TABLES static uint32_t _PyOpcode_RelativeJump[8] = { |