Skip to content

Avoid stop-the-world pause when reassigning __class__ on a uniquely owned instances #145566

@colesbury

Description

@colesbury

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixestopic-free-threading

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions