mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
gh-87729: improve hit rate of LOAD_SUPER_ATTR specialization (#104270)
This commit is contained in:
parent
ddc0e70a32
commit
77262458fe
13 changed files with 374 additions and 352 deletions
|
@ -323,11 +323,8 @@ _PyCode_Quicken(PyCodeObject *code)
|
|||
|
||||
/* Super */
|
||||
|
||||
#define SPEC_FAIL_SUPER_NOT_LOAD_METHOD 9
|
||||
#define SPEC_FAIL_SUPER_BAD_CLASS 10
|
||||
#define SPEC_FAIL_SUPER_SHADOWED 11
|
||||
#define SPEC_FAIL_SUPER_NOT_METHOD 12
|
||||
#define SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND 13
|
||||
#define SPEC_FAIL_SUPER_BAD_CLASS 9
|
||||
#define SPEC_FAIL_SUPER_SHADOWED 10
|
||||
|
||||
/* Attributes */
|
||||
|
||||
|
@ -516,15 +513,10 @@ specialize_module_load_attr(
|
|||
/* Attribute specialization */
|
||||
|
||||
void
|
||||
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
|
||||
_Py_CODEUNIT *instr, PyObject *name, int load_method) {
|
||||
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, _Py_CODEUNIT *instr, int load_method) {
|
||||
assert(ENABLE_SPECIALIZATION);
|
||||
assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
|
||||
_PySuperAttrCache *cache = (_PySuperAttrCache *)(instr + 1);
|
||||
if (!load_method) {
|
||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_LOAD_METHOD);
|
||||
goto fail;
|
||||
}
|
||||
if (global_super != (PyObject *)&PySuper_Type) {
|
||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED);
|
||||
goto fail;
|
||||
|
@ -533,23 +525,8 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *se
|
|||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS);
|
||||
goto fail;
|
||||
}
|
||||
PyTypeObject *tp = (PyTypeObject *)cls;
|
||||
PyObject *res = _PySuper_LookupDescr(tp, self, name);
|
||||
if (res == NULL) {
|
||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND);
|
||||
PyErr_Clear();
|
||||
goto fail;
|
||||
}
|
||||
if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
|
||||
write_u32(cache->class_version, tp->tp_version_tag);
|
||||
write_u32(cache->self_type_version, Py_TYPE(self)->tp_version_tag);
|
||||
write_obj(cache->method, res); // borrowed
|
||||
instr->op.code = LOAD_SUPER_ATTR_METHOD;
|
||||
Py_DECREF(res);
|
||||
goto success;
|
||||
}
|
||||
Py_DECREF(res);
|
||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_METHOD);
|
||||
instr->op.code = load_method ? LOAD_SUPER_ATTR_METHOD : LOAD_SUPER_ATTR_ATTR;
|
||||
goto success;
|
||||
|
||||
fail:
|
||||
STAT_INC(LOAD_SUPER_ATTR, failure);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue