When reassigning my_obj.__class__ = new_class, we should avoid the stop-the-world pause if the object is uniquely referenced.
Context
I've been profiling a multi-threaded Django server 1 to help find scaling bottlenecks in more realistic applications. Django does a lot of __class__ reassignment (e.g., 1, 2, 3), which with our current strategy causes major scaling bottlenecks. We can skip the stop-the-world pause, if the object is uniquely referenced (i.e., we can guarantee no other thread is accessing it). Together with a few other changes, this improves scaling a lot.
Linked PRs
When reassigning
my_obj.__class__ = new_class, we should avoid the stop-the-world pause if the object is uniquely referenced.Context
I've been profiling a multi-threaded Django server 1 to help find scaling bottlenecks in more realistic applications. Django does a lot of
__class__reassignment (e.g., 1, 2, 3), which with our current strategy causes major scaling bottlenecks. We can skip the stop-the-world pause, if the object is uniquely referenced (i.e., we can guarantee no other thread is accessing it). Together with a few other changes, this improves scaling a lot.Linked PRs
__class__on newly created objects (gh-145567) #145567__class__on newly created objects (GH-145567) #145601__class__on newly created objects (gh-145567) #145605Footnotes
Specifically Zulip with some modifications work with 3.14t and threads ↩