pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/145775/files

"https://github.githubassets.com/assets/primer-primitives-10bf9dd67e3d70bd.css" /> gh-145685: Avoid contention on TYPE_LOCK in super() lookups by colesbury · Pull Request #145775 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions Include/internal/pycore_stackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,13 @@ _PyThreadState_PushCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
ref->ref = PyStackRef_NULL;
}

static inline void
_PyThreadState_PushCStackRefNew(PyThreadState *tstate, _PyCStackRef *ref, PyObject *obj)
{
_PyThreadState_PushCStackRef(tstate, ref);
ref->ref = PyStackRef_FromPyObjectNew(obj);
}

static inline void
_PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
{
Expand Down
20 changes: 9 additions & 11 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12360,18 +12360,16 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
PyObject *mro, *res;
Py_ssize_t i, n;

BEGIN_TYPE_LOCK();
mro = lookup_tp_mro(su_obj_type);
/* keep a strong reference to mro because su_obj_type->tp_mro can be
replaced during PyDict_GetItemRef(dict, name, &res) and because
another thread can modify it after we end the critical section
below */
Py_XINCREF(mro);
END_TYPE_LOCK();

if (mro == NULL)
return NULL;

/* Keep a strong reference to mro because su_obj_type->tp_mro can be
replaced during PyDict_GetItemRef(dict, name, &res). */
PyThreadState *tstate = _PyThreadState_GET();
_PyCStackRef mro_ref;
_PyThreadState_PushCStackRefNew(tstate, &mro_ref, mro);

assert(PyTuple_Check(mro));
n = PyTuple_GET_SIZE(mro);

Expand All @@ -12382,7 +12380,7 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
}
i++; /* skip su->type (if any) */
if (i >= n) {
Py_DECREF(mro);
_PyThreadState_PopCStackRef(tstate, &mro_ref);
return NULL;
}

Expand All @@ -12393,13 +12391,13 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *

if (PyDict_GetItemRef(dict, name, &res) != 0) {
// found or error
Py_DECREF(mro);
_PyThreadState_PopCStackRef(tstate, &mro_ref);
return res;
}

i++;
} while (i < n);
Py_DECREF(mro);
_PyThreadState_PopCStackRef(tstate, &mro_ref);
return NULL;
}

Expand Down
16 changes: 16 additions & 0 deletions Tools/ftscalingbench/ftscalingbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ def instantiate_typing_namedtuple():
for _ in range(1000 * WORK_SCALE):
obj = MyTypingNamedTuple(x=1, y=2, z=3)

@register_benchmark
def super_call():
# TODO: super() on the same class from multiple threads still doesn't
# scale well, so use a class per-thread here for now.
class Base:
def method(self):
return 1

class Derived(Base):
def method(self):
return super().method()

obj = Derived()
for _ in range(1000 * WORK_SCALE):
obj.method()


@register_benchmark
def deepcopy():
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy