summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-03-26 16:08:20 (GMT)
committerGitHub <noreply@github.com>2025-03-26 16:08:20 (GMT)
commit3d4ac1a2c2b610f35a9e164878d67185e4a3546f (patch)
tree3f5c5a1347accef950ebfce5d7204864daaf0b41 /Python/bytecodes.c
parent1b8bb1ed0c4243796af531a35de982bc4f028215 (diff)
downloadcpython-3d4ac1a2c2b610f35a9e164878d67185e4a3546f.zip
cpython-3d4ac1a2c2b610f35a9e164878d67185e4a3546f.tar.gz
cpython-3d4ac1a2c2b610f35a9e164878d67185e4a3546f.tar.bz2
gh-123358: Use `_PyStackRef` in `LOAD_DEREF` (gh-130064)
Concurrent accesses from multiple threads to the same `cell` object did not scale well in the free-threaded build. Use `_PyStackRef` and optimistically avoid locking to improve scaling. With the locks around cell reads gone, some of the free threading tests were prone to starvation: the readers were able to run in a tight loop and the writer threads weren't scheduled frequently enough to make timely progress. Adjust the tests to avoid this. Co-authored-by: Donghee Na <donghee.na@python.org>
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 44e8ea2..b6a4821 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -1822,12 +1822,11 @@ dummy_func(
inst(LOAD_DEREF, ( -- value)) {
PyCellObject *cell = (PyCellObject *)PyStackRef_AsPyObjectBorrow(GETLOCAL(oparg));
- PyObject *value_o = PyCell_GetRef(cell);
- if (value_o == NULL) {
+ value = _PyCell_GetStackRef(cell);
+ if (PyStackRef_IsNull(value)) {
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
ERROR_IF(true, error);
}
- value = PyStackRef_FromPyObjectSteal(value_o);
}
inst(STORE_DEREF, (v --)) {