Title: Chained calls with medium/large dict/list literals are slow to typecheck · Issue #9427 · python/mypy · GitHub
Open Graph Title: Chained calls with medium/large dict/list literals are slow to typecheck · Issue #9427 · python/mypy
X Title: Chained calls with medium/large dict/list literals are slow to typecheck · Issue #9427 · python/mypy
Description: 🐛 Bug Report Variable assignments with chained calls converting dict/list literals are surprisingly slow to typecheck. Interestingly, breaking down the assignment into multiple steps often yields noticeable performance improvement. To Re...
Open Graph Description: 🐛 Bug Report Variable assignments with chained calls converting dict/list literals are surprisingly slow to typecheck. Interestingly, breaking down the assignment into multiple steps often yields n...
X Description: 🐛 Bug Report Variable assignments with chained calls converting dict/list literals are surprisingly slow to typecheck. Interestingly, breaking down the assignment into multiple steps often yields n...
Opengraph URL: https://github.com/python/mypy/issues/9427
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Chained calls with medium/large dict/list literals are slow to typecheck","articleBody":"\r\n## 🐛 Bug Report\r\n\r\nVariable assignments with chained calls converting dict/list literals are surprisingly slow to typecheck. Interestingly, breaking down the assignment into multiple steps often yields noticeable performance improvement.\r\n\r\n## To Reproduce\r\n\r\nFor instance, consider:\r\n\r\n```\r\nfrom decimal import Decimal\r\nfrom collections import OrderedDict\r\n\r\nGRID = OrderedDict(sorted({\r\n (93, 659): Decimal('0.3000'), (93, 714): Decimal('0.2950'), (93, 749): Decimal('0.2820'), (93, 799): Decimal('0.2690'), (93, 850): Decimal('0.1990'), # noqa: E501\r\n (94, 659): Decimal('0.3000'), (94, 714): Decimal('0.2900'), (94, 749): Decimal('0.2745'), (94, 799): Decimal('0.2590'), (94, 850): Decimal('0.1820'), # noqa: E501\r\n (95, 659): Decimal('0.3000'), (95, 714): Decimal('0.2850'), (95, 749): Decimal('0.2620'), (95, 799): Decimal('0.2390'), (95, 850): Decimal('0.1620'), # noqa: E501\r\n (96, 659): Decimal('0.3000'), (96, 714): Decimal('0.2800'), (96, 749): Decimal('0.2495'), (96, 799): Decimal('0.2190'), (96, 850): Decimal('0.1570'), # noqa: E501\r\n (97, 659): Decimal('0.2800'), (97, 714): Decimal('0.2750'), (97, 749): Decimal('0.2370'), (97, 799): Decimal('0.1990'), (97, 850): Decimal('0.1520'), # noqa: E501\r\n (98, 659): Decimal('0.2710'), (98, 714): Decimal('0.2650'), (98, 749): Decimal('0.2220'), (98, 799): Decimal('0.1790'), (98, 850): Decimal('0.1470'), # noqa: E501\r\n (99, 659): Decimal('0.2500'), (99, 714): Decimal('0.1990'), (99, 749): Decimal('0.1975'), (99, 799): Decimal('0.1670'), (99, 850): Decimal('0.1170'), # noqa: E501\r\n (100, 659): Decimal('0.2500'), (100, 714): Decimal('0.1890'), (100, 749): Decimal('0.1500'), (100, 799): Decimal('0.1084'), (100, 850): Decimal('0.1000'), # noqa: E501\r\n}.items()))\r\n\r\n```\r\n\r\nand the same broken down into two steps:\r\n\r\n```\r\nfrom decimal import Decimal\r\nfrom collections import OrderedDict\r\n\r\nGRID = {\r\n (93, 659): Decimal('0.3000'), (93, 714): Decimal('0.2950'), (93, 749): Decimal('0.2820'), (93, 799): Decimal('0.2690'), (93, 850): Decimal('0.1990'), # noqa: E501\r\n (94, 659): Decimal('0.3000'), (94, 714): Decimal('0.2900'), (94, 749): Decimal('0.2745'), (94, 799): Decimal('0.2590'), (94, 850): Decimal('0.1820'), # noqa: E501\r\n (95, 659): Decimal('0.3000'), (95, 714): Decimal('0.2850'), (95, 749): Decimal('0.2620'), (95, 799): Decimal('0.2390'), (95, 850): Decimal('0.1620'), # noqa: E501\r\n (96, 659): Decimal('0.3000'), (96, 714): Decimal('0.2800'), (96, 749): Decimal('0.2495'), (96, 799): Decimal('0.2190'), (96, 850): Decimal('0.1570'), # noqa: E501\r\n (97, 659): Decimal('0.2800'), (97, 714): Decimal('0.2750'), (97, 749): Decimal('0.2370'), (97, 799): Decimal('0.1990'), (97, 850): Decimal('0.1520'), # noqa: E501\r\n (98, 659): Decimal('0.2710'), (98, 714): Decimal('0.2650'), (98, 749): Decimal('0.2220'), (98, 799): Decimal('0.1790'), (98, 850): Decimal('0.1470'), # noqa: E501\r\n (99, 659): Decimal('0.2500'), (99, 714): Decimal('0.1990'), (99, 749): Decimal('0.1975'), (99, 799): Decimal('0.1670'), (99, 850): Decimal('0.1170'), # noqa: E501\r\n (100, 659): Decimal('0.2500'), (100, 714): Decimal('0.1890'), (100, 749): Decimal('0.1500'), (100, 799): Decimal('0.1084'), (100, 850): Decimal('0.1000'), # noqa: E501\r\n}\r\n\r\nGG = OrderedDict(sorted(GRID.items()))\r\n```\r\n## Expected Behavior\r\n\r\nI would expect the two samples above to typecheck in roughly equivalent amounts of time.\r\n## Actual Behavior\r\n\r\nVariant 1 is much slower to typecheck than variant 2: roughly 700ms vs 70ms (not using mypyc-compiled version)\r\n\r\nThis seems to arise from a combination of repeated computations when typechecking overloaded methods such as `sorted`, typechecking from root to leaf instead of leaf to root, and not caching resolved types for dict/list exprs.\r\n\r\n## Your Environment\r\n\r\n- Mypy version used: 0.790-dev 5906a5d\r\n- Mypy command-line flags: --ignore-missing-imports --show-traceback\r\n- Python version used: 3.7\r\n- Operating system and version: macOS 10.14.6\r\n","author":{"url":"https://github.com/huguesb","@type":"Person","name":"huguesb"},"datePublished":"2020-09-08T03:24:25Z","url":"https://github.com/python/mypy/issues/9427"}
| 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:8b4fc524-f31f-d9ee-fad8-d938116a4ad1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E328:1A77D:275168:34CE39:6B00241D |
| html-safe-nonce | 43eadb218d324bd5075db9a2eec1bbf3ab736845968c7d079afbd2f8bdd845df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzI4OjFBNzdEOjI3NTE2ODozNENFMzk6NkIwMDI0MUQiLCJ2aXNpdG9yX2lkIjoiMzYwMTA1MTE5MDA4NDc3Mjg5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c31be3be157358935c59fca56c022945a9532d55cd7aefe62ab0611448c36416 |
| hovercard-subject-tag | issue:695514733 |
| 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/mypy/9427/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fe218926a700e0be61797ad842b6c721189460e616e2ec1211dc21ae9e3d1ff/python/mypy/issues/9427 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fe218926a700e0be61797ad842b6c721189460e616e2ec1211dc21ae9e3d1ff/python/mypy/issues/9427 |
| og:image:alt | 🐛 Bug Report Variable assignments with chained calls converting dict/list literals are surprisingly slow to typecheck. Interestingly, breaking down the assignment into multiple steps often yields n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | huguesb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width