Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Feature or enhancement
Following 6d59c9e,typing._ProtocolMeta.__instancecheck__ usesinspect.getattr_static in a tight loop, where it had previously usedhasattr. This improves semantics in several highly desirable ways, but causes a considerable slowdown for_ProtocolMeta.__instancecheck__, asinspect.getattr_static ismuch slower thanhasattr.
The performance hit to_ProtocolMeta.__instancecheck__ has already been mostly mitigated through severaltyping-specific optimisations that are tracked in this issue:
However, it would be good to also see if we can improve the performance ofinspect.getattr_static. This will not only improve the performance ofisinstance() checks against classes subclassingtyping.Protocol. It will also improve the performance of all other tools that useinspect.getattr_static for introspection without side effects.
Linked PRs
- gh-103193: Micro-optimise helper functions for
inspect.getattr_static#103195 - gh-103193: Use LBYL idioms rather than EAFP in
inspect.getattr_static#103318 - gh-103193: Speedup and inline
inspect._is_type#103321 - gh-103193: Celebrate performance improvements to
inspect.getattr_staticin 'What's New in Python 3.12' #103349 - gh-103193: cache calls to
inspect._shadowed_dictininspect.getattr_static#104267 - gh-103193: Improve
getattr_statictest coverage #104286 - [3.11] gh-103193: Improve
getattr_statictest coverage (GH-104286) #104290 - gh-103193: Fix refleaks in
test_inspectandtest_typing#104320