colesbury · GitHub

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

Footnotes

  1. Specifically Zulip with some modifications work with 3.14t and threads

Read the original on github.com ↗