Skip to content

Commit 62ec966

Browse files
committed
Skip stop-the-world in object_set_class for uniquely referenced objects
1 parent c315165 commit 62ec966

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Objects/typeobject.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7170,13 +7170,19 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
71707170
}
71717171

71727172
#ifdef Py_GIL_DISABLED
7173-
PyInterpreterState *interp = _PyInterpreterState_GET();
7174-
_PyEval_StopTheWorld(interp);
7173+
int unique = _PyObject_IsUniquelyReferenced(self);
7174+
PyInterpreterState *interp = NULL;
7175+
if (!unique) {
7176+
interp = _PyInterpreterState_GET();
7177+
_PyEval_StopTheWorld(interp);
7178+
}
71757179
#endif
71767180
PyTypeObject *oldto = Py_TYPE(self);
71777181
int res = object_set_class_world_stopped(self, newto);
71787182
#ifdef Py_GIL_DISABLED
7179-
_PyEval_StartTheWorld(interp);
7183+
if (!unique) {
7184+
_PyEval_StartTheWorld(interp);
7185+
}
71807186
#endif
71817187
if (res == 0) {
71827188
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE) {

0 commit comments

Comments
 (0)