René's URL Explorer Experiment


Title: Wildly inconsistent performance for seemingly trivial changes to source code · Issue #14271 · python/mypy · GitHub

Open Graph Title: Wildly inconsistent performance for seemingly trivial changes to source code · Issue #14271 · python/mypy

X Title: Wildly inconsistent performance for seemingly trivial changes to source code · Issue #14271 · python/mypy

Description: My company is currently using 0.971 internally. I was looking into upgrading to 0.991 and discovered a significant performance regression. Encourage by the recent commit log I tried the master branch as well, which is definitely better b...

Open Graph Description: My company is currently using 0.971 internally. I was looking into upgrading to 0.991 and discovered a significant performance regression. Encourage by the recent commit log I tried the master bran...

X Description: My company is currently using 0.971 internally. I was looking into upgrading to 0.991 and discovered a significant performance regression. Encourage by the recent commit log I tried the master bran...

Opengraph URL: https://github.com/python/mypy/issues/14271

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wildly inconsistent performance for seemingly trivial changes to source code","articleBody":"My company is currently using 0.971 internally. I was looking into upgrading to 0.991 and discovered a significant performance regression. Encourage by the recent commit log I tried the master branch as well, which is definitely better but still much worse than 0.971 on our codebase: roughly 4x slower: from ~300s to ~1200s for whole-codebase run without incremental cache.\r\n\r\nIn the course of narrowing down the slowdown (via per-file and per-line timing stats), I discovered a surprisingly large performance difference for seemingly very similar code. Consider:\r\n\r\n```\r\nfrom typing import Any, Dict\r\n\r\nclass Foo(object):\r\n    def __init__(self) -> None:\r\n        self.field = {\r\n            'XXX': {\r\n                'XXX': 'XXX',\r\n                'XXX': {\r\n                    'XXX': [\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        }\r\n                    ],\r\n                },\r\n                'XXX': {\r\n                    'XXX': [\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': {\r\n                                'XXX': [\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX'\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX'\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                ]\r\n                            },\r\n                            'XXX': {\r\n                                'XXX': [\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 2,\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    },\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    }\r\n                                                ]\r\n                                            },\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': 'XXX',\r\n                                                    }\r\n                                                ]\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                ]\r\n                            }\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': {\r\n                                'XXX': [\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 2,\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    },\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    }\r\n                                                ]\r\n                                            },\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': 'XXX',\r\n                                                    }\r\n                                                ]\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                ]\r\n                            }\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': {\r\n                                'XXX': [\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 2,\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    },\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    }\r\n                                                ]\r\n                                            },\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': 'XXX',\r\n                                                    }\r\n                                                ]\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                ]\r\n                            }\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': {\r\n                                'XXX': [\r\n                                    {\r\n                                        'XXX': {\r\n                                            'XXX': {\r\n                                                'XXX': 2,\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    },\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': {\r\n                                                            'XXX': 'XXX',\r\n                                                            'XXX': 'XXX'\r\n                                                        }\r\n                                                    }\r\n                                                ]\r\n                                            },\r\n                                            'XXX': {\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': 'XXX',\r\n                                                'XXX': [\r\n                                                    {\r\n                                                        'XXX': 'XXX',\r\n                                                        'XXX': 'XXX',\r\n                                                    }\r\n                                                ]\r\n                                            }\r\n                                        }\r\n                                    },\r\n                                ]\r\n                            }\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX',\r\n                            'XXX': None,\r\n                            'XXX': None\r\n                        }\r\n                    ]\r\n                },\r\n                'XXX': {\r\n                    'XXX': 'XXX',\r\n                    'XXX': 'XXX',\r\n                    'XXX': [\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        },\r\n                        {\r\n                            'XXX': 'XXX',\r\n                            'XXX': 'XXX'\r\n                        }\r\n                    ]\r\n                }\r\n            }\r\n        }\r\n\r\n\r\nreveal_type(Foo.field)\r\n\r\n```\r\n\r\nResults in:\r\n\r\n```\r\ntest-san.py:286: note: Revealed type is \"builtins.dict[builtins.str, builtins.dict[builtins.str, typing.Collection[builtins.str]]]\"\r\nSuccess: no issues found in 1 source file\r\n\r\nreal\t0m1.238s\r\nuser\t0m1.140s\r\nsys\t0m0.089s\r\n```\r\n\r\nBut changing the code to:\r\n```\r\nfrom typing import Any, Dict\r\n\r\nclass Foo(object):\r\n    def __init__(self) -> None:\r\n        self.field: Dict[Any, Any] = NotImplemented\r\n\r\n    def reset(self) -> None:\r\n        self.field = {\r\n            # same contents as above...\r\n        }\r\n```\r\n\r\nchanges the runtime quite significantly:\r\n\r\n```\r\ntest-san.py:289: note: Revealed type is \"builtins.dict[Any, Any]\"\r\nSuccess: no issues found in 1 source file\r\n\r\nreal\t0m10.080s\r\nuser\t0m9.790s\r\nsys\t0m0.256s\r\n```\r\n\r\nand a further code change as follows:\r\n```\r\nfrom typing import Any, Dict\r\n\r\nclass Foo(object):\r\n    def __init__(self) -> None:\r\n        self.field = NotImplemented\r\n\r\n    def reset(self) -> None:\r\n        self.field = {\r\n            # same contents as above...\r\n        }\r\n```\r\n\r\nleads to another noticeable perf hit:\r\n```\r\n$ time mypy test-san.py\r\ntest-san.py:9: error: Incompatible types in assignment (expression has type \"Dict[str, Dict[str, Collection[str]]]\", variable has type \"_NotImplementedType\")  [assignment]\r\ntest-san.py:289: note: Revealed type is \"builtins._NotImplementedType\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n\r\nreal\t0m22.067s\r\nuser\t0m21.666s\r\nsys\t0m0.319s\r\n```\r\n\r\nI haven't had time to profile this yet but I suspect it is related to https://github.com/python/mypy/pull/9477 and https://github.com/python/mypy/pull/12707 and that somehow one version of the code hits the optimization and another doesn't\r\n\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: master as of `695ea3017fee084c9d2ec17d9b28f8af905e3b63`, mypyc-compiled\r\n- Mypy command-line flags: N/A\r\n- Mypy configuration options from `mypy.ini` (and other config files): N/A\r\n- Python version used: 3.7.8\r\n- OS: macOS 12.5.1 (x86_64)\r\n\r\n","author":{"url":"https://github.com/huguesb","@type":"Person","name":"huguesb"},"datePublished":"2022-12-10T04:24:20Z","url":"https://github.com/python/mypy/issues/14271"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2134db2d-65ad-d970-e8d4-7f489aa1962a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBB0C:9E1B2:2EAA5B4:3DADC60:6B002407
html-safe-nonce8275233df49e271dd692595b21975fcefb5cd4216aa9feabd8b9bb5d7c3bb73d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjBDOjlFMUIyOjJFQUE1QjQ6M0RBREM2MDo2QjAwMjQwNyIsInZpc2l0b3JfaWQiOiIxNDExMTM4NzU0MTY4NDk3MTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacac89574bace050c72d4a2c95250abf7485b252f8915a6efcf1e8e05da1705179
hovercard-subject-tagissue:1487914719
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/14271/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c8e65eea240387c9cc2d4096aa2481ca472ca9522397c29c1cc42c238d812bb8/python/mypy/issues/14271
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c8e65eea240387c9cc2d4096aa2481ca472ca9522397c29c1cc42c238d812bb8/python/mypy/issues/14271
og:image:altMy company is currently using 0.971 internally. I was looking into upgrading to 0.991 and discovered a significant performance regression. Encourage by the recent commit log I tried the master bran...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamehuguesb
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/14271#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F14271
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F14271
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/issues/14271
Reloadhttps://github.com/python/mypy/issues/14271
Reloadhttps://github.com/python/mypy/issues/14271
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests546 (546)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/14271
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/14271
#19536https://github.com/python/mypy/pull/19536
#14274https://github.com/python/mypy/pull/14274
Wildly inconsistent performance for seemingly trivial changes to source codehttps://github.com/python/mypy/issues/14271#top
#19536https://github.com/python/mypy/pull/19536
#14274https://github.com/python/mypy/pull/14274
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
https://github.com/huguesb
huguesbhttps://github.com/huguesb
on Dec 10, 2022https://github.com/python/mypy/issues/14271#issue-1487914719
#9477https://github.com/python/mypy/pull/9477
#12707https://github.com/python/mypy/pull/12707
huguesbhttps://github.com/huguesb
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
on Dec 10, 2022https://github.com/python/mypy/issues/14271#event-8003373366
https://github.com/huguesb
huguesbhttps://github.com/huguesb
on Dec 10, 2022https://github.com/python/mypy/issues/14271#issuecomment-1345170355
#14274https://github.com/python/mypy/pull/14274
AlexWaygoodhttps://github.com/AlexWaygood
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
on Dec 10, 2022https://github.com/python/mypy/issues/14271#event-8004164537
ilevkivskyihttps://github.com/ilevkivskyi
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#19536https://github.com/python/mypy/pull/19536
on Jul 30, 2025https://github.com/python/mypy/issues/14271#event-18894841554
ilevkivskyihttps://github.com/ilevkivskyi
on Jul 30, 2025https://github.com/python/mypy/issues/14271#event-18894841580
Use cache for DictExpr as well (#19536)https://github.com/python/mypy/commit/0f78f9c578bfbc6fbe4a20888353c20e9691178a
#19536https://github.com/python/mypy/pull/19536
0f78f9chttps://github.com/python/mypy/commit/0f78f9c578bfbc6fbe4a20888353c20e9691178a
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/14271
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/14271
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.