-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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-102213: Optimizing the Performance of __getattr__ #102213 #102248
gh-102213: Optimizing the Performance of __getattr__ #102213 #102248
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
when __getattr__ is defined, python with try to find an attribute using _PyObject_GenericGetAttrWithDict find nothing is reasonable so we don't need an exception, it will hurt performance.
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
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.
Good work. Just a few things I think we should tidy up.
Misc/NEWS.d/next/Core and Builtins/2023-02-26-13-12-55.gh-issue-102213.fTH8X7.rst
Outdated
Show resolved
Hide resolved
Thank you for your advice, it was very helpful. I also think that modifying the public C API could cause issues, but I was unsure whether to put the new function together with |
Also, thanks for addressing my review! In the future once you address the comments, you can just click "resolve conversation". |
Thanks! Congrats on your first commit to CPython @wangxiang-hz ! |
Thank you! It's really my honor to participate in the development of CPython! Looking forward to make more pull requests in the future:) |
…102248) When __getattr__ is defined, python with try to find an attribute using _PyObject_GenericGetAttrWithDict find nothing is reasonable so we don't need an exception, it will hurt performance.
…ythonGH-102248)" This reverts commit aa0a73d.
… `__getattr__` (pythonGH-102248)" (pythonGH-103332) This reverts commit aa0a73d.
This is the corrected version of pythonGH-102248
when
__getattr__
is defined, python with try to find an attribute using_PyObject_GenericGetAttrWithDict
. Find nothing is reasonable so we don't need an exception, it will hurt performance.Using this test code:
Now the result is:
Call __getattr__ spend time: 0.4704132080078125
After this modification, the result is:
Call __getattr__ spend time: 0.07422256469726562