Title: gh-102213: Optimizing the Performance of __getattr__ #102213 by wangxiang-hz · Pull Request #102248 · python/cpython · GitHub
Open Graph Title: gh-102213: Optimizing the Performance of __getattr__ #102213 by wangxiang-hz · Pull Request #102248 · python/cpython
X Title: gh-102213: Optimizing the Performance of __getattr__ #102213 by wangxiang-hz · Pull Request #102248 · python/cpython
Description: 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: import time import sys NUM = 1000000 class AttrObj(object): def __init__(self) -> None: super(AttrObj, self).__init__() self.pps = 2 def __getattr__(self, name): return 4 def main(): start = time.time() for i in range(1, NUM): pass end = time.time() peer = end - start o = AttrObj() print(f"Python version of {sys.version}") start = time.time() for i in range(1, NUM): s = o.ppp end = time.time() print(f"Call __getattr__ spend time: {end - start - peer}") if __name__ == "__main__": main() Now the result is: Call __getattr__ spend time: 0.4704132080078125 After this modification, the result is: Call __getattr__ spend time: 0.07422256469726562 Issue: gh-102213
Open Graph Description: 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. Usi...
X Description: 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....
Opengraph URL: https://github.com/python/cpython/pull/102248
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:8c3513d8-a79a-5451-1a22-f2cadc8e22e7 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | ABEC:1B40D2:4B74F5:6771C8:6969DE2D |
| html-safe-nonce | f738675148f46c403e36815c4c6e35bd97ef7a7b30f6aa4cb4b98944ce419ca6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkVDOjFCNDBEMjo0Qjc0RjU6Njc3MUM4OjY5NjlERTJEIiwidmlzaXRvcl9pZCI6Ijc5NzQ3OTM2MzEwMjIzNjIwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | df0b49c43af19b924f15c316c8a9e3c9d35c7f752441b3f358425dce766a76fd |
| hovercard-subject-tag | pull_request:1254247608 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/102248/checks |
| twitter:image | https://avatars.githubusercontent.com/u/34048878?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/34048878?s=400&v=4 |
| og:image:alt | 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. Usi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width