Title: Performance of attribute lookup for module objects · Issue #104066 · python/cpython · GitHub
Open Graph Title: Performance of attribute lookup for module objects · Issue #104066 · python/cpython
X Title: Performance of attribute lookup for module objects · Issue #104066 · python/cpython
Description: Feature or enhancement Similar to gh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as non-existing attributes on types and insta...
Open Graph Description: Feature or enhancement Similar to gh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as no...
X Description: Feature or enhancement Similar to gh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as no...
Opengraph URL: https://github.com/python/cpython/issues/104066
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Performance of attribute lookup for module objects","articleBody":"# Feature or enhancement\r\n\r\nSimilar to gh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as non-existing attributes on types and instances.\r\n\r\nmicrobenchmark on main:\r\n\r\n```\r\npython -m pyperf timeit -s 'import os' 'hasattr(os, \"getenv\")'\r\n.....................\r\nMean +- std dev: 37.8 ns +- 1.5 ns\r\n```\r\n\r\n```\r\npython -m pyperf timeit -s 'import os' 'hasattr(os, \"nothing\")'\r\n.....................\r\nMean +- std dev: 541 ns +- 16 ns\r\n```\r\n\r\nAs in gh-92216, the reason for the slowness is time spent in creating an `AttributeError`, which is not needed.\r\nBy adding a special case for modules (similar to the type special case in gh-99979), this overhead can be eliminated.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104063\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/itamaro","@type":"Person","name":"itamaro"},"datePublished":"2023-05-01T21:45:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/104066/cpython/issues/104066"}
| 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:d6f252a6-aa05-1030-fa6f-b39bda8f80ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2A8:4BD90:137C588:1B44F58:696A3D74 |
| html-safe-nonce | 9017533d8a4f48a6620a5865dc849b0e4839ba3a5e8855697feb4dd5249818f5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkE4OjRCRDkwOjEzN0M1ODg6MUI0NEY1ODo2OTZBM0Q3NCIsInZpc2l0b3JfaWQiOiI1MTIxNDc0OTcxNjk4NjIwMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5b732cf8b899374d5f109b2c3f133c0da8b61f23bcb296cd312171fa70bae44d |
| hovercard-subject-tag | issue:1691450990 |
| 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/104066/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c55940bd11d9ecbdc60070450cf398d2ba4fa59d3e776dfa00d766dd58da4f72/python/cpython/issues/104066 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c55940bd11d9ecbdc60070450cf398d2ba4fa59d3e776dfa00d766dd58da4f72/python/cpython/issues/104066 |
| og:image:alt | Feature or enhancement Similar to gh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as no... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | itamaro |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| 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 | 13581a31d51edf4a3aca179e10890a4d4f9b6d76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width