Title: Optimise `inspect.getattr_static` · Issue #103193 · python/cpython · GitHub
Open Graph Title: Optimise `inspect.getattr_static` · Issue #103193 · python/cpython
X Title: Optimise `inspect.getattr_static` · Issue #103193 · python/cpython
Description: Feature or enhancement Following 6d59c9e, typing._ProtocolMeta.__instancecheck__ uses inspect.getattr_static in a tight loop, where it had previously used hasattr. This improves semantics in several highly desirable ways, but causes a co...
Open Graph Description: Feature or enhancement Following 6d59c9e, typing._ProtocolMeta.__instancecheck__ uses inspect.getattr_static in a tight loop, where it had previously used hasattr. This improves semantics in severa...
X Description: Feature or enhancement Following 6d59c9e, typing._ProtocolMeta.__instancecheck__ uses inspect.getattr_static in a tight loop, where it had previously used hasattr. This improves semantics in severa...
Opengraph URL: https://github.com/python/cpython/issues/103193
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optimise `inspect.getattr_static`","articleBody":"# Feature or enhancement\r\n\r\nFollowing 6d59c9e, `typing._ProtocolMeta.__instancecheck__` uses `inspect.getattr_static` in a tight loop, where it had previously used `hasattr`. This improves semantics in several highly desirable ways, but causes a considerable slowdown for `_ProtocolMeta.__instancecheck__`, as `inspect.getattr_static` is _much_ slower than `hasattr`.\r\n\r\nThe performance hit to `_ProtocolMeta.__instancecheck__` has already been mostly mitigated through several `typing`-specific optimisations that are tracked in this issue:\r\n\r\n- https://github.com/python/cpython/issues/74690\r\n\r\nHowever, it would be good to also see if we can improve the performance of `inspect.getattr_static`. This will not only improve the performance of `isinstance()` checks against classes subclassing `typing.Protocol`. It will also improve the performance of all other tools that use `inspect.getattr_static` for introspection without side effects.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103195\n* gh-103318\n* gh-103321\n* gh-103349\n* gh-104267\n* gh-104286\n* gh-104290\n* gh-104320\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-04-02T16:32:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/103193/cpython/issues/103193"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c0f246cb-5e46-e84a-5ff5-c9b8c4892a50 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9424:2F31CD:9F74CD:DBB7D8:6969ED2C |
| html-safe-nonce | ea2933bf9f6edaee210f7d7599314d43a617a67899403a8b751619d85a8543e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDI0OjJGMzFDRDo5Rjc0Q0Q6REJCN0Q4OjY5NjlFRDJDIiwidmlzaXRvcl9pZCI6IjQ0MjQ5ODc4ODA2NDc2ODMzNzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8182b6319e22f68d7637287135a8e54459bed6ba29e1b538e95aa9f2e41f38fe |
| hovercard-subject-tag | issue:1651011100 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/103193/issue_layout |
| twitter:image | https://opengraph.githubassets.com/59962caa0312199a1adf600973ad8f03815cafcd1ef6f2678e4cdeae64b84f46/python/cpython/issues/103193 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/59962caa0312199a1adf600973ad8f03815cafcd1ef6f2678e4cdeae64b84f46/python/cpython/issues/103193 |
| og:image:alt | Feature or enhancement Following 6d59c9e, typing._ProtocolMeta.__instancecheck__ uses inspect.getattr_static in a tight loop, where it had previously used hasattr. This improves semantics in severa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexWaygood |
| 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 |
| 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