Skip to content

[mypyc] Make type objects immortal if using free threading #19538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2025

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy