Skip to content

bpo-46072: Improve LOAD_METHOD stats #31104

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ initial_counter_value(void) {
#define SPEC_FAIL_BUILTIN_CLASS_METHOD 17
#define SPEC_FAIL_CLASS_METHOD_OBJ 18
#define SPEC_FAIL_OBJECT_SLOT 19
#define SPEC_FAIL_HAS_DICT 20
#define SPEC_FAIL_HAS_MANAGED_DICT 21
#define SPEC_FAIL_INSTANCE_ATTRIBUTE 22
#define SPEC_FAIL_METACLASS_ATTRIBUTE 23

/* Binary subscr */

Expand Down Expand Up @@ -954,7 +958,7 @@ load_method_fail_kind(DescriptorClassification kind)
case NON_DESCRIPTOR:
return SPEC_FAIL_NOT_DESCRIPTOR;
case ABSENT:
return SPEC_FAIL_EXPECTED_ERROR;
return SPEC_FAIL_INSTANCE_ATTRIBUTE;
}
Py_UNREACHABLE();
}
Expand All @@ -975,6 +979,16 @@ specialize_class_load_method(PyObject *owner, _Py_CODEUNIT *instr, PyObject *nam
cache2->obj = descr;
*instr = _Py_MAKECODEUNIT(LOAD_METHOD_CLASS, _Py_OPARG(*instr));
return 0;
#ifdef Py_STATS
case ABSENT:
if (_PyType_Lookup(Py_TYPE(owner), name) != NULL) {
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_METACLASS_ATTRIBUTE);
}
else {
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_EXPECTED_ERROR);
}
return -1;
#endif
default:
SPECIALIZATION_FAIL(LOAD_METHOD, load_method_fail_kind(kind));
return -1;
Expand Down Expand Up @@ -1024,7 +1038,7 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
if (owner_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
PyObject **owner_dictptr = _PyObject_ManagedDictPointer(owner);
if (*owner_dictptr) {
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_IS_ATTR);
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_HAS_MANAGED_DICT);
goto fail;
}
PyDictKeysObject *keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
Expand All @@ -1046,7 +1060,7 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
*instr = _Py_MAKECODEUNIT(LOAD_METHOD_NO_DICT, _Py_OPARG(*instr));
}
else {
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_IS_ATTR);
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_HAS_DICT);
goto fail;
}
}
Expand Down