@@ -114,6 +114,7 @@ As a consequence of this, split keys have a maximum size of 16.
114114#include "Python.h"
115115#include "pycore_bitutils.h" // _Py_bit_length
116116#include "pycore_call.h" // _PyObject_CallNoArgs()
117+ #include "pycore_code.h" // stats
117118#include "pycore_dict.h" // PyDictKeysObject
118119#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
119120#include "pycore_object.h" // _PyObject_GC_TRACK()
@@ -4990,6 +4991,7 @@ _PyObject_InitializeDict(PyObject *obj)
49904991 return 0 ;
49914992 }
49924993 if (tp -> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
4994+ OBJECT_STAT_INC (new_values );
49934995 return init_inline_values (obj , tp );
49944996 }
49954997 PyObject * dict ;
@@ -5033,6 +5035,7 @@ _PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values)
50335035{
50345036 assert (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT );
50355037 PyDictKeysObject * keys = CACHED_KEYS (Py_TYPE (obj ));
5038+ OBJECT_STAT_INC (dict_materialized_on_request );
50365039 return make_dict_from_instance_attributes (keys , values );
50375040}
50385041
@@ -5051,6 +5054,14 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
50515054 PyErr_SetObject (PyExc_AttributeError , name );
50525055 return -1 ;
50535056 }
5057+ #ifdef Py_STATS
5058+ if (shared_keys_usable_size (keys ) > 14 ) {
5059+ OBJECT_STAT_INC (dict_materialized_too_big );
5060+ }
5061+ else {
5062+ OBJECT_STAT_INC (dict_materialized_new_key );
5063+ }
5064+ #endif
50545065 PyObject * dict = make_dict_from_instance_attributes (keys , values );
50555066 if (dict == NULL ) {
50565067 return -1 ;
@@ -5183,6 +5194,7 @@ PyObject_GenericGetDict(PyObject *obj, void *context)
51835194 PyObject * * dictptr = _PyObject_ManagedDictPointer (obj );
51845195 if (* values_ptr ) {
51855196 assert (* dictptr == NULL );
5197+ OBJECT_STAT_INC (dict_materialized_on_request );
51865198 * dictptr = dict = make_dict_from_instance_attributes (CACHED_KEYS (tp ), * values_ptr );
51875199 if (dict != NULL ) {
51885200 * values_ptr = NULL ;
0 commit comments