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-92216: improve performance of hasattr for type objects #99979
Conversation
Thanks! If I understand correctly, the speedup comes from not having to raise and clear an exception right? |
Exactly. This was already happening for the objects with |
|
Name | Link |
---|---|
c689b92 | |
https://app.netlify.com/sites/python-cpython-preview/deploys/639b9d8fa912e80008dd983a | |
https://deploy-preview-99979--python-cpython-preview.netlify.app | |
To edit notification comments on pull requests, go to your Netlify site settings.
@Fidget-Spinner Would you be able to review this PR? |
@eendebakpt alright. Sorry I've been putting this off because the code it touches isn't something I'm super familiar with. However I will take a look at the other examples you pointed out that uses a similar concept. |
This PR improves performance of
hasattr
for type objects in the case the attribute is missing.The optimization is similar to the one used for objects which have
PyObject_GenericGetAttr
as the attribute lookup method(see specialization for PyObject_GenericGetAttr in _PyObject_LookupAttr and suppress in _PyObject_GenericGetAttrWithDict )
Benchmark:
Results: