Skip to content
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

Free-threaded builds can experience heavy contention on PyType_IsSubtype #116868

Closed
DinoV opened this issue Mar 15, 2024 · 0 comments
Closed

Free-threaded builds can experience heavy contention on PyType_IsSubtype #116868

DinoV opened this issue Mar 15, 2024 · 0 comments
Assignees
Labels
performance Performance or resource usage topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@DinoV
Copy link
Contributor

DinoV commented Mar 15, 2024

Bug report

Bug description:

PyType_IsSubtype takes the type lock to ensure that MRO is being accessed in a thread-safe manner as it needs to read and incref it. This can result in heavy contention in some pretty common scenarios (e.g. when sys.setprofile is used we experience heavy contention across threads doing PyCFunction_Check, profiling simple workloads can be nearly 50% slower in some cases). We can avoid this by using Py_TryIncref and only fallback to the lock when the MRO isn't yet shared.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@DinoV DinoV added the type-bug An unexpected behavior, bug, or error label Mar 15, 2024
@DinoV DinoV self-assigned this Mar 15, 2024
@DinoV DinoV added performance Performance or resource usage topic-free-threading labels Mar 15, 2024
DinoV added a commit that referenced this issue Mar 15, 2024
Make PyType_IsSubType not acquire lock
@DinoV DinoV closed this as completed Mar 15, 2024
vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant