Skip to content

Commit 4f977e0

Browse files
committed
Add scaling benchmark and fix refcount contention on type
1 parent 6142b58 commit 4f977e0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Objects/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
19991999
}
20002000

20012001
Py_INCREF(name);
2002-
Py_INCREF(tp);
2002+
_Py_INCREF_TYPE(tp);
20032003

20042004
PyThreadState *tstate = _PyThreadState_GET();
20052005
_PyCStackRef cref;
@@ -2074,7 +2074,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
20742074
}
20752075
done:
20762076
_PyThreadState_PopCStackRef(tstate, &cref);
2077-
Py_DECREF(tp);
2077+
_Py_DECREF_TYPE(tp);
20782078
Py_DECREF(name);
20792079
return res;
20802080
}

Tools/ftscalingbench/ftscalingbench.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ def deepcopy():
264264
for i in range(40 * WORK_SCALE):
265265
copy.deepcopy(x)
266266

267+
@register_benchmark
268+
def setattr_non_interned():
269+
prefix = sys.implementation.name
270+
obj = MyObject()
271+
for _ in range(1000 * WORK_SCALE):
272+
setattr(obj, f"{prefix}_a", None)
273+
setattr(obj, f"{prefix}_b", None)
274+
setattr(obj, f"{prefix}_c", None)
275+
267276

268277
def bench_one_thread(func):
269278
t0 = time.perf_counter_ns()

0 commit comments

Comments
 (0)