Title: Inspect module is prohibitively expensive to import · Issue #117865 · python/cpython · GitHub
Open Graph Title: Inspect module is prohibitively expensive to import · Issue #117865 · python/cpython
X Title: Inspect module is prohibitively expensive to import · Issue #117865 · python/cpython
Description: From post by @AlexWaygood in #117372 (comment)_: I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib? dataclasses is an unfortunately heavy import, yes. Although ...
Open Graph Description: From post by @AlexWaygood in #117372 (comment)_: I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib? dataclasses is an un...
X Description: From post by @AlexWaygood in #117372 (comment)_: I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib? dataclasses ...
Opengraph URL: https://github.com/python/cpython/issues/117865
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inspect module is prohibitively expensive to import","articleBody":"From post by @AlexWaygood in https://github.com/python/cpython/issues/117372#issuecomment-2047024740_:\r\n\r\n> > I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib?\r\n>\r\n> `dataclasses` is an unfortunately heavy import, yes. Although it imports relatively few modules itself, one of those modules is `inspect`, which has a _huge_ import time (`inspect` imports half the standard library). In the past, I've looked into removing the `dataclasses` dependency on `inspect`, but couldn't see a way to do so without making the code significantly more ugly; the same goes when it comes to improving the import time for `inspect` itself. (In hindsight, I'd argue `inspect` should probably have been a package rather than a huge single-file Python module... but hindsight is 20/20.)\r\n\r\nPerhaps inspect could be refactored to limit the import-time cost.\r\n\r\nCurrently on my m3 mac pro, on the second attempt, the import times are 1.2ms and 7.9ms (cumulative):\r\n\r\n```\r\n cpython main @ ./python.exe -X importtime -c 'import inspect' 2> /dev/null ; ./python.exe -X importtime -c 'import inspect' 2>1 | grep -E '(cumul|inspect)'\r\nimport time: self [us] | cumulative | imported package\r\nimport time: 1184 | 7892 | inspect\r\n```\r\n\r\nI've searched the issue tracker and didn't see anything tracking this concern, so right now it's a naïve feature request.\r\n\r\nRelated: https://github.com/python/cpython/issues/108901\r\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-119526\n* gh-119546\n* gh-144756\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jaraco","@type":"Person","name":"jaraco"},"datePublished":"2024-04-14T10:27:22Z","url":"https://github.com/python/cpython/issues/117865"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:087abef8-3ef8-05cd-0781-17dc6851d0eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95E0:1D86C4:3DF0121:4EAC959:6B020F6F |
| html-safe-nonce | 4071029dbdf3860621dbab9c1b5acd2240bf516f523d5ec135338debf61ce930 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUUwOjFEODZDNDozREYwMTIxOjRFQUM5NTk6NkIwMjBGNkYiLCJ2aXNpdG9yX2lkIjoiMjE0NzYzNDk0ODYwODIzMzMyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 632f407f3918db1c139e64bf66f6c34f5aab7904a6ea5be38434c59af861dbb5 |
| hovercard-subject-tag | issue:2242086904 |
| 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/117865/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c7c6c31b5a9a1fe309f5258ddc6336568afaad3b14d3e0cfec0335f7af45c99a/python/cpython/issues/117865 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c7c6c31b5a9a1fe309f5258ddc6336568afaad3b14d3e0cfec0335f7af45c99a/python/cpython/issues/117865 |
| og:image:alt | From post by @AlexWaygood in #117372 (comment)_: I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib? dataclasses is an un... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jaraco |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width