Skip to content

[3.14] gh-162752: Skip stop-the-world when a type slot update changes nothing (gh-162763) - #162849

Merged
nascheme merged 1 commit into
python:3.14from
nascheme:gh-162752-slot-fastpath-3.14
Nov 30, 2026
Merged

nascheme merged 1 commit into
python:3.14from
nascheme:gh-162752-slot-fastpath-3.14

Conversation

@nascheme

@nascheme nascheme commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Assigning a special method to a class stopped the world on every assignment, even when no slot changed (e.g. replacing one Python getitem function with another). With other threads contending, each pause could cost about 1 ms. Before stopping the world, compute the new slot values with TYPE_LOCK held and skip the pause if none would change.

The check walks tp_subclasses with only TYPE_LOCK held, so also hold TYPE_LOCK when type_dealloc() removes a type from the subclasses of its bases. That part of gh-151377 was not backported to 3.14.

(cherry picked from commit c52b7a8)

Co-authored-by: Gregory P. Smith greg@krypto.org

…hanges nothing (pythongh-162763)

Assigning a special method to a class stopped the world on every
assignment, even when no slot changed (e.g. replacing one Python
__getitem__ function with another).  With other threads contending, each
pause could cost about 1 ms.  Before stopping the world, compute the new
slot values with TYPE_LOCK held and skip the pause if none would change.

The check walks tp_subclasses with only TYPE_LOCK held, so also hold
TYPE_LOCK when type_dealloc() removes a type from the subclasses of its
bases.  That part of pythongh-151377 was not backported to 3.14.

(cherry picked from commit c52b7a8)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @nascheme for commit cac6ede 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F162849%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 30, 2026
@nascheme
nascheme merged commit 00cefa8 into python:3.14 Nov 30, 2026
136 of 139 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-free-threading type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants