KEMBAR78
[mypyc] Make type objects immortal if using free threading by JukkaL · Pull Request #19538 · python/mypy · GitHub
Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 30, 2025

If they are not immortal, concurrent construction of objects by multiple
threads can cause serious contention due to reference count updates.

Making them immortal is similar to how both user-defined normal Python
classes and built-in types in free-threaded builds are immortal.

Fix the issue for both native and non-native classes. Dataclasses still have
contention, and they may be harder to fix (this may require a fix in CPython).

This speeds up a few micro-benchmarks that construct instances of classes
in multiple threads by a big factor (5x+).

JukkaL added 3 commits July 30, 2025 10:50
If they are not immortal, concurrent construction objects by multiple
threads can cause serious contention due to reference count updates.

This is similar how user-defined normal Python classes in free-threaded
builds are immmortal.

This speeds up a micro-benchmark that constructs instances of a native
class in multiple threads by a big factor (5x+).
@JukkaL JukkaL merged commit 5750690 into master Jul 30, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-type-immortal branch July 30, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants