You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following 6d59c9e, typing._ProtocolMeta.__instancecheck__ uses inspect.getattr_static in a tight loop, where it had previously used hasattr. This improves semantics in several highly desirable ways, but causes a considerable slowdown for _ProtocolMeta.__instancecheck__, as inspect.getattr_static is much slower than hasattr.
The performance hit to _ProtocolMeta.__instancecheck__ has already been mostly mitigated through several typing-specific optimisations that are tracked in this issue:
However, it would be good to also see if we can improve the performance of inspect.getattr_static. This will not only improve the performance of isinstance() checks against classes subclassing typing.Protocol. It will also improve the performance of all other tools that use inspect.getattr_static for introspection without side effects.
Activity
pythongh-103193: Micro-optimise helper functions for `inspect.getattr…
gh-103193: Micro-optimise helper functions for `inspect.getattr_stati…
AlexWaygood commentedon Apr 5, 2023
I can't see anything further that can be easily optimised here, but happy to reopen if somebody else can!
sobolevn commentedon Apr 5, 2023
I've measured my ideas, but the results are close to noise.
Initial numbers:
After all changes:
Code:
pythongh-103193: Use LBYL idioms rather than EAFP in `inspect.getattr…
gh-103193: Use LBYL idioms rather than EAFP in `inspect.getattr_stati…
pythongh-103193: Speedup and inline `inspect._is_type`
gh-103193: Speedup and inline `inspect._is_type` (#103321)
AlexWaygood commentedon Apr 6, 2023
I think I'm once again out of ideas, at least for now.
10 remaining items
pythongh-103193: Improve `getattr_static` test coverage
gh-103193: Improve `getattr_static` test coverage (#104286)
pythongh-103193: Improve `getattr_static` test coverage (pythonGH-104286
[3.11] gh-103193: Improve `getattr_static` test coverage (GH-104286) (#…
pythongh-103193: cache calls to `inspect._shadowed_dict` in `inspect.…
pythongh-103193: Improve `getattr_static` test coverage (python#104286)
Merge branch 'main' into inlinecomp2
pythongh-103193: Fix refleaks in `test_inspect` and `test_typing`
gh-103193: Fix refleaks in `test_inspect` and `test_typing` (#104320)
Merge branch 'main' into inlinecomp2
Merge branch 'main' into fixsendfamily
Merge branch 'main' into supermon
Merge branch 'main' into fixloadsuperspec
namka279 commentedon Jul 21, 2024