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)istype.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.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response