Title: GC performance regression in free threaded build · Issue #132917 · python/cpython · GitHub
Open Graph Title: GC performance regression in free threaded build · Issue #132917 · python/cpython
X Title: GC performance regression in free threaded build · Issue #132917 · python/cpython
Description: Bug report Bug description: I've identified a significant performance regression when using Python's free-threaded mode with shared list appends. In my test case, simply appending to a shared list causes a 10-15x performance decrease com...
Open Graph Description: Bug report Bug description: I've identified a significant performance regression when using Python's free-threaded mode with shared list appends. In my test case, simply appending to a shared list ...
X Description: Bug report Bug description: I've identified a significant performance regression when using Python's free-threaded mode with shared list appends. In my test case, simply appending to a shar...
Opengraph URL: https://github.com/python/cpython/issues/132917
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"GC performance regression in free threaded build","articleBody":"# Bug report\n\n### Bug description:\n\nI've identified a significant performance regression when using Python's free-threaded mode with shared list appends. In my test case, simply appending to a shared list causes a 10-15x performance decrease compared to normal Python operation.\n\nTest Case:\n```python\nimport itertools\nimport time\n\ndef performance_test(n_options=5, n_items=5, iterations=50):\n list = []\n \n def expensive_operation():\n # Create lists of tuples\n data = []\n for _ in range(n_options):\n data.append([(f\"a{i}\", f\"b{i}\") for i in range(n_items)])\n \n # Generate all combinations and create result tuples\n results = []\n for combo in itertools.product(*data):\n result = tuple((x[0], x[1], f\"name_{i}\") for i, x in enumerate(combo))\n results.append(result)\n \n # Commenting the following line solves the performance regression in free-threaded mode\n list.append(results)\n return results\n\n start = time.time()\n for _ in range(iterations):\n result = expensive_operation()\n \n duration = time.time() - start\n print(f\"n_options={n_options}, n_items={n_items}, iterations={iterations}\")\n print(f\"Time: {duration:.4f}s, Combinations: {len(result)}\")\n return duration\n\nif __name__ == \"__main__\":\n print(\"Python Performance Regression Test\")\n print(\"-\" * 40)\n performance_test()\n```\n\nResults:\n- Standard Python3.13: 0.1290s\n- Free-threaded Python3.13t: 2.1643s\n- Free-threaded Python 3.14.0a7: 2.1923s\n- Free-threaded Python3.13t with list.append commented out: 0.1332s\n\nThe regression appears to be caused by contention on the per-list locks and reference count fields when appending to a shared list in free-threaded mode.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-133399\n* gh-133464\n* gh-133508\n* gh-133544\n* gh-133718\n* gh-134692\n* gh-134802\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gptsarthak","@type":"Person","name":"gptsarthak"},"datePublished":"2025-04-25T09:55:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/132917/cpython/issues/132917"}
| 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:3aa59e58-a0eb-5997-d0da-452c4cbd6650 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A644:242722:5C1C84:7C872B:6A52F927 |
| html-safe-nonce | f1433ae0753d3b9f8dcf6030e9dd855d745bcd89bfab43581562a7943ff45f28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjQ0OjI0MjcyMjo1QzFDODQ6N0M4NzJCOjZBNTJGOTI3IiwidmlzaXRvcl9pZCI6IjExMzIzOTUxMzYxMjg1Nzk4NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 75e599ac99038873f5d1b01820e55a7d59655242510492a85a0087adb48c8223 |
| hovercard-subject-tag | issue:3019575271 |
| 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/132917/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de7166497b09e1b671f8af1d1c46bf7d5a9541302c7de8594e404d6e1abdf2f7/python/cpython/issues/132917 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de7166497b09e1b671f8af1d1c46bf7d5a9541302c7de8594e404d6e1abdf2f7/python/cpython/issues/132917 |
| og:image:alt | Bug report Bug description: I've identified a significant performance regression when using Python's free-threaded mode with shared list appends. In my test case, simply appending to a shared list ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gptsarthak |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width