@@ -114,6 +114,7 @@ As a consequence of this, split keys have a maximum size of 16.
114
114
#include "Python.h"
115
115
#include "pycore_bitutils.h" // _Py_bit_length
116
116
#include "pycore_call.h" // _PyObject_CallNoArgs()
117
+ #include "pycore_code.h" // stats
117
118
#include "pycore_dict.h" // PyDictKeysObject
118
119
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
119
120
#include "pycore_object.h" // _PyObject_GC_TRACK()
@@ -4990,6 +4991,7 @@ _PyObject_InitializeDict(PyObject *obj)
4990
4991
return 0 ;
4991
4992
}
4992
4993
if (tp -> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
4994
+ OBJECT_STAT_INC (new_values );
4993
4995
return init_inline_values (obj , tp );
4994
4996
}
4995
4997
PyObject * dict ;
@@ -5033,6 +5035,7 @@ _PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values)
5033
5035
{
5034
5036
assert (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT );
5035
5037
PyDictKeysObject * keys = CACHED_KEYS (Py_TYPE (obj ));
5038
+ OBJECT_STAT_INC (dict_materialized_on_request );
5036
5039
return make_dict_from_instance_attributes (keys , values );
5037
5040
}
5038
5041
@@ -5051,6 +5054,14 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
5051
5054
PyErr_SetObject (PyExc_AttributeError , name );
5052
5055
return -1 ;
5053
5056
}
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
5054
5065
PyObject * dict = make_dict_from_instance_attributes (keys , values );
5055
5066
if (dict == NULL ) {
5056
5067
return -1 ;
@@ -5183,6 +5194,7 @@ PyObject_GenericGetDict(PyObject *obj, void *context)
5183
5194
PyObject * * dictptr = _PyObject_ManagedDictPointer (obj );
5184
5195
if (* values_ptr ) {
5185
5196
assert (* dictptr == NULL );
5197
+ OBJECT_STAT_INC (dict_materialized_on_request );
5186
5198
* dictptr = dict = make_dict_from_instance_attributes (CACHED_KEYS (tp ), * values_ptr );
5187
5199
if (dict != NULL ) {
5188
5200
* values_ptr = NULL ;
0 commit comments