Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
Move stats for the method cache into thePy_STAT
machinery#100255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -327,18 +327,6 @@ static unsigned int | ||
_PyType_ClearCache(PyInterpreterState *interp) | ||
{ | ||
struct type_cache *cache = &interp->types.type_cache; | ||
// Set to None, rather than NULL, so _PyType_Lookup() can | ||
// use Py_SETREF() rather than using slower Py_XSETREF(). | ||
type_cache_clear(cache, Py_None); | ||
@@ -4147,6 +4135,24 @@ find_name_in_mro(PyTypeObject *type, PyObject *name, int *error) | ||
return res; | ||
} | ||
/* Check if the "readied" PyUnicode name | ||
is a double-underscore special name. */ | ||
static int | ||
is_dunder_name(PyObject *name) | ||
{ | ||
Py_ssize_t length = PyUnicode_GET_LENGTH(name); | ||
int kind = PyUnicode_KIND(name); | ||
/* Special names contain at least "__x__" and are always ASCII. */ | ||
if (length > 4 && kind == PyUnicode_1BYTE_KIND) { | ||
const Py_UCS1 *characters = PyUnicode_1BYTE_DATA(name); | ||
return ( | ||
((characters[length-2] == '_') && (characters[length-1] == '_')) && | ||
((characters[0] == '_') && (characters[1] == '_')) | ||
); | ||
} | ||
return 0; | ||
} | ||
/* Internal API to look for a name through the MRO. | ||
This returns a borrowed reference, and doesn't set an exception! */ | ||
PyObject * | ||
@@ -4160,12 +4166,13 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) | ||
struct type_cache_entry *entry = &cache->hashtable[h]; | ||
if (entry->version == type->tp_version_tag && | ||
entry->name == name) { | ||
assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)); | ||
OBJECT_STAT_INC_COND(type_cache_hits, !is_dunder_name(name)); | ||
OBJECT_STAT_INC_COND(type_cache_dunder_hits, is_dunder_name(name)); | ||
return entry->value; | ||
} | ||
OBJECT_STAT_INC_COND(type_cache_misses, !is_dunder_name(name)); | ||
OBJECT_STAT_INC_COND(type_cache_dunder_misses, is_dunder_name(name)); | ||
Comment on lines +4174 to +4175 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I assume there's no user of these stats who will care that the definition of a "miss" now includes collisions whereas before it excluded collisions? Obviously the same information is derivable either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The old stats were only available if | ||
/* We may end up clearing live exceptions below, so make sure it's ours. */ | ||
assert(!PyErr_Occurred()); | ||
@@ -4193,14 +4200,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) | ||
entry->version = type->tp_version_tag; | ||
entry->value = res; /* borrowed */ | ||
assert(_PyASCIIObject_CAST(name)->hash != -1); | ||
OBJECT_STAT_INC_COND(type_cache_collisions, entry->name != Py_None && entry->name != name); | ||
assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)); | ||
Py_SETREF(entry->name, Py_NewRef(name)); | ||
} | ||
@@ -4217,24 +4217,6 @@ _PyType_LookupId(PyTypeObject *type, _Py_Identifier *name) | ||
return _PyType_Lookup(type, oname); | ||
} | ||
/* This is similar to PyObject_GenericGetAttr(), | ||
but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ | ||
static PyObject * | ||