René's URL Explorer Experiment


Title: Poor thread scaling when constructing instances or accessing attributes · Issue #139103 · python/cpython · GitHub

Open Graph Title: Poor thread scaling when constructing instances or accessing attributes · Issue #139103 · python/cpython

X Title: Poor thread scaling when constructing instances or accessing attributes · Issue #139103 · python/cpython

Description: Bug report Remaining scaling bugs dataclass namedtuple enum Bug description: When constructing dataclass or NamedTuple instances on multiple threads (on a free threading build), or accessing enum class attributes, performance doesn't sca...

Open Graph Description: Bug report Remaining scaling bugs dataclass namedtuple enum Bug description: When constructing dataclass or NamedTuple instances on multiple threads (on a free threading build), or accessing enum c...

X Description: Bug report Remaining scaling bugs dataclass namedtuple enum Bug description: When constructing dataclass or NamedTuple instances on multiple threads (on a free threading build), or accessing enum c...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Poor thread scaling when constructing instances or accessing attributes","articleBody":"# Bug report\n\n### Remaining scaling bugs\n\n- [x] dataclass\n- [x] namedtuple\n- [ ] enum\n\n### Bug description:\n\nWhen constructing dataclass or NamedTuple instances on multiple threads (on a free threading build), or accessing enum class attributes, performance doesn't scale when using multiple threads.\n\nRegular class example (scales well):\n```python\n# b_regular_class.py\nfrom threading import Thread\nfrom time import time\nimport sys\n\nclass Foo:\n    def __init__(self, x):\n        self.x = x\n\nniter = 5 * 1000 * 1000\n\ndef benchmark(n):\n    for i in range(n):\n        Foo(x=1)\n\nfor nth in (1, 4):\n    t0 = time()\n    threads = [Thread(target=benchmark, args=(niter,)) for _ in range(nth)]\n    for t in threads:\n        t.start()\n    for t in threads:\n        t.join()\n    print(f\"{nth=} {(time() - t0) / nth}\")\n```\n\nDataclass example (doesn't scale well):\n```py\n# b_dataclass.py\nfrom threading import Thread\nfrom dataclasses import dataclass\nfrom time import time\nimport sys\n\n@dataclass\nclass Foo:\n    x: int\n\nniter = 5 * 1000 * 1000\n\ndef benchmark(n):\n    for i in range(n):\n        Foo(x=1)\n\nfor nth in (1, 4):\n    t0 = time()\n    threads = [Thread(target=benchmark, args=(niter,)) for _ in range(nth)]\n    for t in threads:\n        t.start()\n    for t in threads:\n        t.join()\n    print(f\"{nth=} {(time() - t0) / nth}\")\n```\n\nNamed tuple example (doesn't scale well):\n```py\n# b_namedtuple.py\nfrom threading import Thread\nfrom typing import NamedTuple\nfrom time import time\nimport sys\n\nclass Foo(NamedTuple):\n    x: int\n\nniter = 5 * 1000 * 1000\n\ndef benchmark(n):\n    for i in range(n):\n        Foo(x=1)\n\nfor nth in (1, 4):\n    t0 = time()\n    threads = [Thread(target=benchmark, args=(niter,)) for _ in range(nth)]\n    for t in threads:\n        t.start()\n    for t in threads:\n        t.join()\n    print(f\"{nth=} {(time() - t0) / nth}\")\n```\n\nEnum example (doesn't scale well):\n```py\n# b_enum.py\nfrom threading import Thread\nfrom time import time\nfrom enum import Enum\nimport sys\n\nclass Foo(Enum):\n    X = 1\n    Y = 2\n\nniter = 5 * 1000 * 1000\n\ndef benchmark(n):\n    for i in range(n):\n        Foo.X\n        Foo.Y.value\n\nfor nth in (1, 4):\n    t0 = time()\n    threads = [Thread(target=benchmark, args=(niter,)) for _ in range(nth)]\n    for t in threads:\n        t.start()\n    for t in threads:\n        t.join()\n    print(f\"{nth=} {(time() - t0) / nth}\")\n```\nResults on recent main branch (running on an EC2 instance):\n```\n(cpython-dev) jukka@jukka-coder-dbx free-threading-benchmarks $ py b_regular_class.py\nnth=1 1.1085155010223389\nnth=4 0.2796591520309448\n(cpython-dev) jukka@jukka-coder-dbx free-threading-benchmarks $ py b_dataclass.py\nnth=1 1.1910037994384766\nnth=4 1.0931583642959595\n(cpython-dev) jukka@jukka-coder-dbx free-threading-benchmarks $ py b_namedtuple.py\nnth=1 1.5688557624816895\nnth=4 2.0257126092910767\n(cpython-dev) jukka@jukka-coder-dbx free-threading-benchmarks $ py b_enum.py\nnth=1 0.9439797401428223\nnth=4 2.272495985031128\n```\nThe expected behavior is that when using 4 threads (`nth=4`), the elapsed time per benchmark iteration (the second printed value) goes down significantly compared to when using a single thread (`nth=1`), which happens with the first benchmark (`b_regular_class.py`) but not the others.\n\ncc @colesbury (we discussed this at CPython Core Dev Sprint in person)\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-141596\n* gh-141603\n* gh-141750\n* gh-144332\n* gh-144406\n* gh-144407\n* gh-144977\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2025-09-18T09:29:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/139103/cpython/issues/139103"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:9c22d6ce-a33c-204c-da99-664b065b8fe8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA5BE:2A9631:273B06:35C54C:6A558F9C
html-safe-nonce674ce9c0b678307c62eed823e642b7909388b7481dcaf8226e1fc1d0275645d8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUJFOjJBOTYzMToyNzNCMDY6MzVDNTRDOjZBNTU4RjlDIiwidmlzaXRvcl9pZCI6Ijc2NTE5NzA1MzI5ODUxMTQ1MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac269d65591123cbdf318ac766abe390171d1cd6e64539c2f4267f568ee18192b0
hovercard-subject-tagissue:3429494310
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/139103/issue_layout
twitter:imagehttps://opengraph.githubassets.com/831c3400ab3022ddfbe2de59f2320985a279a9131deedfbfc4e25919c3d643d0/python/cpython/issues/139103
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/831c3400ab3022ddfbe2de59f2320985a279a9131deedfbfc4e25919c3d643d0/python/cpython/issues/139103
og:image:altBug report Remaining scaling bugs dataclass namedtuple enum Bug description: When constructing dataclass or NamedTuple instances on multiple threads (on a free threading build), or accessing enum c...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJukkaL
hostnamegithub.com
expected-hostnamegithub.com
Noneb5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e
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
releaseaa21baa44893467b0b640d0300538f84ca8c475b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/139103#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F139103
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F139103
Sign up https://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/139103
Reloadhttps://github.com/python/cpython/issues/139103
Reloadhttps://github.com/python/cpython/issues/139103
Please reload this pagehttps://github.com/python/cpython/issues/139103
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/139103
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Poor thread scaling when constructing instances or accessing attributeshttps://github.com/python/cpython/issues/139103#top
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
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Sep 18, 2025https://github.com/python/cpython/issues/139103#issue-3429494310
@colesburyhttps://github.com/colesbury
gh-139103: fix free-threading dataclass.__init__ perf issue #141596https://github.com/python/cpython/pull/141596
Draft: gh-139103: Use _PyObject_GetMethodStackRef for slot_tp_new #141603https://github.com/python/cpython/pull/141603
[3.14] gh-139103: fix free-threading dataclass.__init__ perf issue (gh-141596) #141750https://github.com/python/cpython/pull/141750
gh-139103: Improve namedtuple scaling in free-threaded build #144332https://github.com/python/cpython/pull/144332
gh-139103: Use METH_FASTCALL for tp_new_wrapper #144406https://github.com/python/cpython/pull/144406
gh-139103: Use borrowed references for positional args in _PyStack_UnpackDict #144407https://github.com/python/cpython/pull/144407
gh-139103: Improve enum free-threaded scaling #144977https://github.com/python/cpython/pull/144977
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
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%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.