8000 gh-115999: Specialize `LOAD_SUPER_ATTR` in free-threaded builds by nascheme · Pull Request #127128 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115999: Specialize LOAD_SUPER_ATTR in free-threaded builds #127128

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 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert change to _PySuper_Lookup().
It seems `do_super_lookup()` and `supercheck()` are safe to call and so
`_PySuper_Lookup()` doesn't need a lock for the type object.  This
avoids a performance regression in FT builds.
  • Loading branch information
nascheme committed Nov 26, 2024
commit 1f5f2a2ba36139c047a7a6c8105c128fdfbd2a66
7 changes: 2 additions & 5 deletions Include/internal/pycore_typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,8 @@ extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);

extern PyTypeObject _PyBufferWrapper_Type;

PyAPI_FUNC(PyObject*) _PySuper_LookupAttr(PyTypeObject *su_type, PyObject *su_obj,
PyObject *name);

PyAPI_FUNC(PyObject*) _PySuper_LookupMethod(PyTypeObject *su_type, PyObject *su_obj,
PyObject *name, int *method_found);
PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
PyObject *name, int *meth_found);

extern PyObject* _PyType_GetFullyQualifiedName(PyTypeObject *type, char sep);

Expand Down
26 changes: 2 additions & 24 deletions Objects/typeobject.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -11600,8 +11600,8 @@ supercheck(PyTypeObject *type, PyObject *obj)
return NULL;
}

static PyObject *
super_lookup_lock_held(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *method)
PyObject *
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *method)
{
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
if (su_obj_type == NULL) {
Expand All @@ -11612,28 +11612,6 @@ super_lookup_lock_held(PyTypeObject *su_type, PyObject *su_obj, PyObject *name,
return res;
}

PyObject *
_PySuper_LookupAttr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name)
{
PyObject *res;
BEGIN_TYPE_LOCK();
res = super_lookup_lock_held(su_type, su_obj, name, NULL);
END_TYPE_LOCK();
return res;
}

PyObject *
_PySuper_LookupMethod(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *method_found)
{
PyObject *res;
BEGIN_TYPE_LOCK();
*method_found = 0;
res = super_lookup_lock_held(su_type, su_obj, name,
Py_TYPE(su_obj)->tp_getattro == PyObject_GenericGetAttr ? method_found : NULL);
END_TYPE_LOCK()
return res;
}

static PyObject *
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
Expand Down
7 changes: 4 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "pycore_typeobject.h" // _PySuper_LookupAttr() _PySuper_LookupMethod()
#include "pycore_typeobject.h" // _PySuper_Lookup()

#include "pycore_dict.h"
#include "dictobject.h"
Expand Down Expand Up @@ -2001,7 +2001,7 @@ dummy_func(
DEOPT_IF(!PyType_Check(class));
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
PyObject *attr = _PySuper_LookupAttr((PyTypeObject *)class, self, name);
PyObject *attr = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
DECREF_INPUTS();
ERROR_IF(attr == NULL, error);
attr_st = PyStackRef_FromPyObjectSteal(attr);
Expand All @@ -2019,7 +2019,8 @@ dummy_func(
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
PyTypeObject *cls = (PyTypeObject *)class;
int method_found = 0;
PyObject *attr_o = _PySuper_LookupMethod(cls, self, name, &method_found);
PyObject *attr_o = _PySuper_Lookup(cls, self, name,
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? &method_found : NULL);
PyStackRef_CLOSE(global_super_st);
PyStackRef_CLOSE(class_st);
if (attr_o == NULL) {
Expand Down
5 changes: 3 additions & 2 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0