-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Lock contention inside _PyType_LookupRef #132380
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Proposal:
As part of adding free-threading support to LibCST, we noticed there is a lot of lock contention on
TYPE_LOCKinside the_PyType_LookupReffunction. In the LibCST, the common "visitor" pattern is used. For example, in the_visitors.pymodule there is the code:The second argument to
getattr()is a non-interned string and it causes the cached and lock-free path of_PyType_LookupRef()never to be taken. Instead, theTYPE_LOCKmutex is acquired on each lookup. This obviously scales very badly if there are multiple threads looking up class methods using this pattern.Testing was done with Python 3.13 but I believe the same issue exists with 3.14.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs