-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-103193: Speedup and inline inspect._is_type
#103321
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The improvements keep on coming!
objtype = type(obj) | ||
if type not in _static_getmro(objtype): | ||
klass = objtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has equivalent semantics with less code and fewer assignments, but perhaps it muddies the semantics of the klass
var a bit (since it will temporarily be "wrong" in the case that obj
is already a type.) No strong feelings, whatever you prefer.
objtype = type(obj) | |
if type not in _static_getmro(objtype): | |
klass = objtype | |
klass = type(obj) | |
if type not in _static_getmro(klass): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Yeah, I see what you mean, but I think I'd prefer to keep the semantics of klass
clear here :)
Optimisations will continue until morale improves! |
Improve performance of `inspect.getattr_static`
(Using @sobolevn's benchmark script from #103193 (comment).)
Benchmarks on
main
:Benchmarks with this PR:
This speeds up this
isinstance()
call 1.25x relative tomain
:inspect.getattr_static
#103193