René's URL Explorer Experiment


Title: sets with >30 elements not constant-folded in `in`/`not in` and `for` loops · Issue #148817 · python/cpython · GitHub

Open Graph Title: sets with >30 elements not constant-folded in `in`/`not in` and `for` loops · Issue #148817 · python/cpython

X Title: sets with >30 elements not constant-folded in `in`/`not in` and `for` loops · Issue #148817 · python/cpython

Description: Bug report Bug description: Since gh-126835 (moving constant folding from AST to CFG), set and list literals with more than 30 constant elements are no longer constant-folded in in/not in membership tests and for loop iteration. This cau...

Open Graph Description: Bug report Bug description: Since gh-126835 (moving constant folding from AST to CFG), set and list literals with more than 30 constant elements are no longer constant-folded in in/not in membershi...

X Description: Bug report Bug description: Since gh-126835 (moving constant folding from AST to CFG), set and list literals with more than 30 constant elements are no longer constant-folded in in/not in membershi...

Opengraph URL: https://github.com/python/cpython/issues/148817

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sets with >30 elements not constant-folded in `in`/`not in` and `for` loops","articleBody":"# Bug report\n\n### Bug description:\n\nSince gh-126835 (moving constant folding from AST to CFG), set and list literals with more than 30 constant elements are no longer constant-folded in `in`/`not in` membership tests and `for` loop iteration. This causes the collection to be rebuilt from scratch on every evaluation instead of being stored as a compile-time constant.\n\nFor example:\n```python\nimport dis\n\n# 30 elements: folded to frozenset constant\ndis.dis(\"x in {%s}\" % \", \".join(str(i) for i in range(1, 31)))\n#   LOAD_NAME   x\n#   LOAD_CONST  frozenset({1, 2, ..., 30})\n#   CONTAINS_OP\n\n# 31 elements: NOT folded, set rebuilt every time (BAD)\ndis.dis(\"x in {%s}\" % \", \".join(str(i) for i in range(1, 32)))\n#   LOAD_NAME   x\n#   BUILD_SET   0\n#   LOAD_SMALL_INT 1\n#   SET_ADD     1\n#   ... (31 x LOAD + SET_ADD)\n#   CONTAINS_OP\n```\n\nUsing a set-membership check with a set literal with 50 elements as a microbenchmark, this manifests as a ~20x slowdown from 3.13 to 3.14:\n\n```python\nimport timeit, sys\nelts = \", \".join(str(i) for i in range(50))\nt = timeit.timeit(f\"25 in {{{elts}}}\", number=1_000_000)\nprint(f\"25 in {{0..49}}: {t:.3f}s\")\n```\n\nPython 3.13.13: 25 in {0..49}: 0.015s\nPython 3.14.4: 25 in {0..49}: 0.291s\n\nIt also affects code object size:\n\n```python\nfor n in [30, 31, 50, 100]:\n    elts = \", \".join(str(i) for i in range(1, n + 1))\n    code = compile(f\"x in {{{elts}}}\", \"\u003ctest>\", \"eval\")\n    print(f\"x in {{1..{n}}}: {len(code.co_code):>5} bytes, {len(code.co_consts)} const(s)\")\n```\n\nPython 3.13.13:\n\n```\nx in {1..30}:    12 bytes, 1 const(s)\nx in {1..31}:    12 bytes, 1 const(s)\nx in {1..50}:    12 bytes, 1 const(s)\nx in {1..100}:    12 bytes, 1 const(s)\n```\n\nPython 3.14.4:\n\n```\nx in {1..30}:    12 bytes, 2 const(s)\nx in {1..31}:   136 bytes, 1 const(s)\nx in {1..50}:   212 bytes, 1 const(s)\nx in {1..100}:   412 bytes, 1 const(s)\n```\n\n\n### CPython versions tested on:\n\n3.15, CPython main branch, 3.14\n\n### Operating systems tested on:\n\nmacOS, Linux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149016\n* gh-155897\n* gh-155898\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/itamaro","@type":"Person","name":"itamaro"},"datePublished":"2026-04-21T00:40:41Z","url":"https://github.com/python/cpython/issues/148817"}

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:90841d0f-662b-5263-50bf-0a98cf1a40e3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB718:23E48:ABEDC5:D757AA:6B0231C5
html-safe-nonce133cfa97e6060cf46958a5ef7b944b07a6ef29e7374269d622e8368648bbd7d4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzE4OjIzRTQ4OkFCRURDNTpENzU3QUE6NkIwMjMxQzUiLCJ2aXNpdG9yX2lkIjoiMzA0NzcwMDI2NTIzMTg1NjA2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac230b07c1fe537d35d2e54ce4a1f26ef9f9f620396b133902049cc84d2b49e44b
hovercard-subject-tagissue:4299535918
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/cpython/148817/issue_layout
twitter:imagehttps://opengraph.githubassets.com/87cb3e56e3dff6466886c501752cf4e4fcf1741e81c802771b87fbba13c4a68c/python/cpython/issues/148817
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/87cb3e56e3dff6466886c501752cf4e4fcf1741e81c802771b87fbba13c4a68c/python/cpython/issues/148817
og:image:altBug report Bug description: Since gh-126835 (moving constant folding from AST to CFG), set and list literals with more than 30 constant elements are no longer constant-folded in in/not in membershi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameitamaro
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/148817#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F148817
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%2Fcpython%2Fissues%2F148817
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%2Fcpython
Reloadhttps://github.com/python/cpython/issues/148817
Reloadhttps://github.com/python/cpython/issues/148817
Reloadhttps://github.com/python/cpython/issues/148817
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/148817
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/148817
sets with >30 elements not constant-folded in in/not in and for loopshttps://github.com/python/cpython/issues/148817#top
https://github.com/Eclips4
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issue-4299535918
gh-126835https://github.com/python/cpython/issues/126835
gh-148817: Fold long lists/sets of constant elements into constant tuples/frozensets #149016https://github.com/python/cpython/pull/149016
[3.15] gh-148817: Fold long lists/sets of constant elements into constant tuples/frozensets (GH-149016) #155897https://github.com/python/cpython/pull/155897
[3.14] gh-148817: Fold long lists/sets of constant elements into constant tu… #155898https://github.com/python/cpython/pull/155898
itamarohttps://github.com/itamaro
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Apr 21, 2026https://github.com/python/cpython/issues/148817#event-24699569634
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4285166018
@Eclips4https://github.com/Eclips4
@iritkatrielhttps://github.com/iritkatriel
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4287940719
picnixzhttps://github.com/picnixz
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
on Apr 21, 2026https://github.com/python/cpython/issues/148817#event-24714360115
Eclips4https://github.com/Eclips4
on Apr 21, 2026https://github.com/python/cpython/issues/148817#event-24724413879
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4290976434
https://github.com/numpy/numpy/blob/388bd75829842d8230147f57eba5f86bb3ad6c3c/numpy/f2py/crackfortran.py#L253-L261https://github.com/numpy/numpy/blob/388bd75829842d8230147f57eba5f86bb3ad6c3c/numpy/f2py/crackfortran.py#L253-L261
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4291031323
https://github.com/iritkatriel
iritkatrielhttps://github.com/iritkatriel
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4291135182
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4291630241
140e69chttps://github.com/python/cpython/commit/140e69c4a878d7a0a26d4406bdad55e56ddae0b7
3618240https://github.com/python/cpython/commit/3618240624d98de2a68a79dc174d49efb96cc2e6
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 21, 2026https://github.com/python/cpython/issues/148817#issuecomment-4291751524
@picnixzhttps://github.com/picnixz
https://github.com/kumaraditya303
kumaraditya303https://github.com/kumaraditya303
on Apr 22, 2026https://github.com/python/cpython/issues/148817#issuecomment-4293406306
https://github.com/Eclips4
Eclips4https://github.com/Eclips4
on Apr 22, 2026https://github.com/python/cpython/issues/148817#issuecomment-4298921026
@itamarohttps://github.com/itamaro
https://github.com/itamaro
itamarohttps://github.com/itamaro
on Apr 22, 2026https://github.com/python/cpython/issues/148817#issuecomment-4299034356
@itamarohttps://github.com/itamaro
@Eclips4https://github.com/Eclips4
itamaro@6c9b972https://github.com/itamaro/cpython/commit/6c9b972f97a24271a2d816de31e2e9c4c288cd81
https://github.com/Eclips4
Eclips4https://github.com/Eclips4
on Apr 22, 2026https://github.com/python/cpython/issues/148817#issuecomment-4299149277
https://github.com/Eclips4
Eclips4https://github.com/Eclips4
on Apr 26, 2026https://github.com/python/cpython/issues/148817#issuecomment-4321785794
#146456https://github.com/python/cpython/pull/146456
https://github.com/Eclips4
Eclips4https://github.com/Eclips4
on Apr 26, 2026https://github.com/python/cpython/issues/148817#issuecomment-4322443051
#149016https://github.com/python/cpython/pull/149016
@iritkatrielhttps://github.com/iritkatriel
@itamarohttps://github.com/itamaro
Eclips4https://github.com/Eclips4
on Aug 16, 2026https://github.com/python/cpython/issues/148817#event-29522277851
gh-148817: Fold long lists/sets of constant elements into constant tu…https://github.com/python/cpython/commit/084230eb2d46a701fe059aa7cec6b2aa1be75814
gh-148817https://github.com/python/cpython/issues/148817
084230ehttps://github.com/python/cpython/commit/084230eb2d46a701fe059aa7cec6b2aa1be75814
[3.14] gh-148817: Fold long lists/sets of constant elements into cons…https://github.com/python/cpython/commit/12e77ac0f34489ea72c9ce5f6e0287591e979857
gh-148817https://github.com/python/cpython/issues/148817
12e77achttps://github.com/python/cpython/commit/12e77ac0f34489ea72c9ce5f6e0287591e979857
hugovkhttps://github.com/hugovk
on Aug 19, 2026https://github.com/python/cpython/issues/148817#event-29658770349
[3.15] gh-148817: Fold long lists/sets of constant elements into cons…https://github.com/python/cpython/commit/fc65b1504c2608e4381da714a02f378b14ed223f
gh-148817https://github.com/python/cpython/issues/148817
fc65b15https://github.com/python/cpython/commit/fc65b1504c2608e4381da714a02f378b14ed223f
hugovkhttps://github.com/hugovk
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 31, 2026https://github.com/python/cpython/issues/148817#event-30273807206
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/148817
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/148817
Eclips4https://github.com/Eclips4
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%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.