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
Performance of attribute lookup for type objects #92216
Comments
Related to this issue, I am wondering if we can consider EDIT: Ah, I half thought it was not fully internal API right now, but "semi" exposed. |
Also see: #76752 (PRs where |
I'll look if it is possible to speed up lookup of the absent attribute in a class object. |
The method `PyUFuncOverride_GetNonDefaultArrayUfunc` is expensive on numpy scalars because these objects do not have a `__array_ufunc__` set and for a missing attribute lookup cpython generates an exception that is later cleared by numpy. This is a performance bottleneck, see #21455. An issue has been submitted to cpython (python/cpython#92216). But even if this is addressed in cpython, it will take untill python 3.12+ before this will be useable by numpy. As an alternative solution, this PR adds a fast path to `PyUFuncOverride_GetNonDefaultArrayUfunc` to determine whether an object is a numpy scalar.
@eendebakpt thanks for the improvement. Can I close this issue now or do you plan to submit more PRs? |
eendebakpt commentedMay 3, 2022
•
edited by bedevere-bot
Bug report
The performance of attribute lookup for type objects is worse than for other objects. A benchmark
Results:
The reason seems to be that the
type_getattro
always executesPyErr_Format
, wheras for the "normal" attribute lookup this is avoided (see here and here)Notes:
Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: