Feature or enhancement
Proposal:
inspect._check_class walks an MRO and calls _shadowed_dict(type(entry))
per entry. Performance can be improved by:
- Adding a fast path for the common case where
type(entry) is type. type.__dict__ is never shadowed, so the answer is unconditionally _sentinel.
- A large percentage of consecutive MRO entries share their metaclass.
Pyperformance results on typing_runtime_protocols:
main 139 ± 2 µs
+ type shortcut 111 ± 1 µs 1.25x faster
+ last-metaclass cache 104 ± 1 µs 1.34x faster
Continues the optimization work in gh-103193 / gh-74690.
@AlexWaygood
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Feature or enhancement
Proposal:
inspect._check_classwalks an MRO and calls_shadowed_dict(type(entry))per entry. Performance can be improved by:
type(entry)istype.type.__dict__is never shadowed, so the answer is unconditionally_sentinel.Pyperformance results on
typing_runtime_protocols:Continues the optimization work in gh-103193 / gh-74690.
@AlexWaygood
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs