Repository navigation
Unexpected scaling bottleneck in _PyType_Lookup / _PyType_LookupStackRefAndVersion #145685
Copy link
Copy link
Closed
Closed
Copy link
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usage
on Mar 9, 2026 - added 8 commits that reference this issue
on Mar 9, 2026 - added a commit that references this issue
on Mar 10, 2026 7 remaining items
- added 4 commits that reference this issue
on Apr 25, 2026 @colesbury @kumaraditya303 After daf09e1
_PySeqLockis not used anywhere anymore:maurycy@gimel cpython (main 9ccd5bb) % rg _PySeqLock Objects/typeobject.c 11:#include "pycore_lock.h" // _PySeqLock_* Include/internal/pycore_lock.h 221:} _PySeqLock; 224:PyAPI_FUNC(void) _PySeqLock_LockWrite(_PySeqLock *seqlock); 227:PyAPI_FUNC(void) _PySeqLock_UnlockWrite(_PySeqLock *seqlock); 231:PyAPI_FUNC(void) _PySeqLock_AbandonWrite(_PySeqLock *seqlock); 234:PyAPI_FUNC(uint32_t) _PySeqLock_BeginRead(_PySeqLock *seqlock); 238:PyAPI_FUNC(int) _PySeqLock_EndRead(_PySeqLock *seqlock, uint32_t previous); 242:PyAPI_FUNC(int) _PySeqLock_AfterFork(_PySeqLock *seqlock); Python/lock.c 579:void _PySeqLock_LockWrite(_PySeqLock *seqlock) 600:void _PySeqLock_AbandonWrite(_PySeqLock *seqlock) 607:void _PySeqLock_UnlockWrite(_PySeqLock *seqlock) 614:uint32_t _PySeqLock_BeginRead(_PySeqLock *seqlock) 625:int _PySeqLock_EndRead(_PySeqLock *seqlock, uint32_t previous) 640:int _PySeqLock_AfterFork(_PySeqLock *seqlock)
Shall we remove it?
- Yeah, I think we can remove it.…On Wed, Aug 5, 2026 at 8:35 AM Maurycy Pawłowski-Wieroński < ***@***.***> wrote: @colesbury <https://github.com/colesbury> @kumaraditya303 <https://github.com/kumaraditya303> After daf09e1 <daf09e1> _PySeqLock is not used anywhere anymore: ***@***.*** cpython (main 9ccd5bb) % rg _PySeqLock Objects/typeobject.c 11:#include "pycore_lock.h" // _PySeqLock_* Include/internal/pycore_lock.h 221:} _PySeqLock; 224:PyAPI_FUNC(void) _PySeqLock_LockWrite(_PySeqLock *seqlock); 227:PyAPI_FUNC(void) _PySeqLock_UnlockWrite(_PySeqLock *seqlock); 231:PyAPI_FUNC(void) _PySeqLock_AbandonWrite(_PySeqLock *seqlock); 234:PyAPI_FUNC(uint32_t) _PySeqLock_BeginRead(_PySeqLock *seqlock); 238:PyAPI_FUNC(int) _PySeqLock_EndRead(_PySeqLock *seqlock, uint32_t previous); 242:PyAPI_FUNC(int) _PySeqLock_AfterFork(_PySeqLock *seqlock); Python/lock.c 579:void _PySeqLock_LockWrite(_PySeqLock *seqlock) 600:void _PySeqLock_AbandonWrite(_PySeqLock *seqlock) 607:void _PySeqLock_UnlockWrite(_PySeqLock *seqlock) 614:uint32_t _PySeqLock_BeginRead(_PySeqLock *seqlock) 625:int _PySeqLock_EndRead(_PySeqLock *seqlock, uint32_t previous) 640:int _PySeqLock_AfterFork(_PySeqLock *seqlock) Shall we remove it? — Reply to this email directly, view it on GitHub <#145685 (comment)> or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAFAD6U4DIY7GN2GGOG2ZML5IMS2BBFKMF2HI4TJMJ2XIZLTTGBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFUQ2TGOBTURXGC3LFVBQWG5DPOJPWSZECUV3GC3DVMWUTKMZWHA3TCNZXGCSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKJVGM3TAMRZG44DTJDOMFWWLKLIMFZV63DBMJSWZAVFOZQWY5LFVI3DCNBQGQZDMNZRGOSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRWHEZDIOBYGEYDIMVENZQW2ZNJNBQXGX3MMFRGK3ECUV3GC3DVMWVDQNJXGQ2DENZQGMY2I3TBNVS2S2DBONPWYYLCMVWKY43VMJVGKY3UL52HS4DFVREXG43VMVBW63LNMVXHJJTUN5YGSY3TSKBKI5DZOBS2U4TFOBXXG2LUN5ZHTJLWMFWHKZNIHAYTKOJYHE3DDAVEOR4XAZNFNFZXG5LFUV3GC3DVMWVDIMBUGY2DSNRRHA2KO5DSNFTWOZLSUZRXEZLBORSQ> . You are receiving this email because you are subscribed to this thread. Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub> .
- added a commit that references this issue
on Sep 27, 2026
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
There are scaling bottlenecks in the slow paths of
_PyType_LookupStackRefAndVersion(), and it turns out that these can be a major bottleneck in larger applications.For context, I've been testing Zulip with 3.14t and multithreading. The problem is basically:
The slow path for this case acquires the global type lock.
We should avoid acquiring the global type lock if the type already has a valid version tag. We'll also want to avoid reference count contention on the MRO tuple.
Linked PRs
_PySeqLockthat is not used anymore (gh-155243) #155243