Title: Do not track immutable tuples in PyTuple_Pack · Issue #139389 · python/cpython · GitHub
Open Graph Title: Do not track immutable tuples in PyTuple_Pack · Issue #139389 · python/cpython
X Title: Do not track immutable tuples in PyTuple_Pack · Issue #139389 · python/cpython
Description: Feature or enhancement Proposal: When we use PyTuple_Pack all objects already well constructed. If we know that they immutable we can skip tracking it in GC, because GC will untrack them eventually. I have a PR ready and benchmark result...
Open Graph Description: Feature or enhancement Proposal: When we use PyTuple_Pack all objects already well constructed. If we know that they immutable we can skip tracking it in GC, because GC will untrack them eventually...
X Description: Feature or enhancement Proposal: When we use PyTuple_Pack all objects already well constructed. If we know that they immutable we can skip tracking it in GC, because GC will untrack them eventually...
Opengraph URL: https://github.com/python/cpython/issues/139389
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Do not track immutable tuples in PyTuple_Pack","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nWhen we use `PyTuple_Pack` all objects already well constructed. If we know that they immutable we can skip tracking it in GC, because GC will untrack them eventually. \n\nI have a PR ready and benchmark results:\n\u003cdetails\u003e\u003csummary\u003eGeometric mean: 1.01x faster (Win11 x64, 11th Gen Intel(R) Core(TM) i5-11600K @ 3.90GHz, 48d0d0dd9733eae4935f2ebd31bef786d8074fc8)\u003c/summary\u003e\n\n\nAll benchmarks:\n===============\n```\n+--------------------------+----------+------------------------+\n| Benchmark | main | tuples |\n+==========================+==========+========================+\n| async_generators | 435 ms | 430 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| asyncio_tcp | 750 ms | 756 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| asyncio_tcp_ssl | 1.91 sec | 1.92 sec: 1.01x slower |\n+--------------------------+----------+------------------------+\n| comprehensions | 22.1 us | 21.8 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| bench_mp_pool | 104 ms | 103 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| bench_thread_pool | 1.29 ms | 1.27 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| coroutines | 28.2 ms | 27.7 ms: 1.02x faster |\n+--------------------------+----------+------------------------+\n| coverage | 88.5 ms | 86.3 ms: 1.02x faster |\n+--------------------------+----------+------------------------+\n| crypto_pyaes | 90.1 ms | 86.7 ms: 1.04x faster |\n+--------------------------+----------+------------------------+\n| deepcopy | 310 us | 307 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| deepcopy_memo | 36.4 us | 36.1 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| deltablue | 5.19 ms | 4.85 ms: 1.07x faster |\n+--------------------------+----------+------------------------+\n| django_template | 45.5 ms | 45.8 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| docutils | 2.47 sec | 2.45 sec: 1.01x faster |\n+--------------------------+----------+------------------------+\n| dulwich_log | 86.2 ms | 86.9 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| fannkuch | 449 ms | 441 ms: 1.02x faster |\n+--------------------------+----------+------------------------+\n| float | 85.3 ms | 82.5 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| create_gc_cycles | 1.17 ms | 1.17 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| gc_traversal | 2.97 ms | 2.88 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| generators | 43.0 ms | 41.6 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| genshi_text | 28.9 ms | 28.7 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| go | 160 ms | 153 ms: 1.04x faster |\n+--------------------------+----------+------------------------+\n| hexiom | 8.39 ms | 8.13 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| json_dumps | 8.62 ms | 8.69 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| logging_format | 12.5 us | 12.2 us: 1.02x faster |\n+--------------------------+----------+------------------------+\n| logging_silent | 139 ns | 140 ns: 1.01x slower |\n+--------------------------+----------+------------------------+\n| logging_simple | 11.3 us | 11.1 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| mako | 14.2 ms | 14.4 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| mdp | 1.47 sec | 1.50 sec: 1.02x slower |\n+--------------------------+----------+------------------------+\n| meteor_contest | 104 ms | 102 ms: 1.02x faster |\n+--------------------------+----------+------------------------+\n| nbody | 114 ms | 113 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| pickle_pure_python | 439 us | 436 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| pprint_safe_repr | 953 ms | 916 ms: 1.04x faster |\n+--------------------------+----------+------------------------+\n| pprint_pformat | 1.95 sec | 1.88 sec: 1.04x faster |\n+--------------------------+----------+------------------------+\n| pyflate | 506 ms | 492 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| python_startup | 28.5 ms | 27.4 ms: 1.04x faster |\n+--------------------------+----------+------------------------+\n| python_startup_no_site | 23.2 ms | 22.2 ms: 1.05x faster |\n+--------------------------+----------+------------------------+\n| raytrace | 361 ms | 345 ms: 1.05x faster |\n+--------------------------+----------+------------------------+\n| regex_compile | 146 ms | 146 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| regex_effbot | 2.03 ms | 2.02 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| regex_v8 | 23.9 ms | 22.7 ms: 1.06x faster |\n+--------------------------+----------+------------------------+\n| richards | 66.1 ms | 59.9 ms: 1.10x faster |\n+--------------------------+----------+------------------------+\n| richards_super | 71.6 ms | 68.7 ms: 1.04x faster |\n+--------------------------+----------+------------------------+\n| scimark_fft | 300 ms | 294 ms: 1.02x faster |\n+--------------------------+----------+------------------------+\n| scimark_lu | 135 ms | 131 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| scimark_monte_carlo | 83.3 ms | 82.4 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| scimark_sor | 157 ms | 150 ms: 1.05x faster |\n+--------------------------+----------+------------------------+\n| scimark_sparse_mat_mult | 4.27 ms | 4.35 ms: 1.02x slower |\n+--------------------------+----------+------------------------+\n| spectral_norm | 122 ms | 118 ms: 1.03x faster |\n+--------------------------+----------+------------------------+\n| sqlglot_optimize | 60.7 ms | 60.9 ms: 1.00x slower |\n+--------------------------+----------+------------------------+\n| sympy_expand | 501 ms | 503 ms: 1.00x slower |\n+--------------------------+----------+------------------------+\n| sympy_sum | 143 ms | 144 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| sympy_str | 287 ms | 292 ms: 1.02x slower |\n+--------------------------+----------+------------------------+\n| telco | 7.26 ms | 7.33 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| tomli_loads | 2.23 sec | 2.25 sec: 1.01x slower |\n+--------------------------+----------+------------------------+\n| typing_runtime_protocols | 189 us | 185 us: 1.02x faster |\n+--------------------------+----------+------------------------+\n| unpack_sequence | 65.4 ns | 68.7 ns: 1.05x slower |\n+--------------------------+----------+------------------------+\n| unpickle | 13.9 us | 14.1 us: 1.01x slower |\n+--------------------------+----------+------------------------+\n| unpickle_pure_python | 303 us | 300 us: 1.01x faster |\n+--------------------------+----------+------------------------+\n| xml_etree_parse | 130 ms | 130 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| xml_etree_iterparse | 107 ms | 108 ms: 1.01x slower |\n+--------------------------+----------+------------------------+\n| xml_etree_process | 79.2 ms | 78.6 ms: 1.01x faster |\n+--------------------------+----------+------------------------+\n| Geometric mean | (ref) | 1.01x faster |\n+--------------------------+----------+------------------------+\n```\n\nBenchmark hidden because not significant (20): 2to3, chaos, deepcopy_reduce, genshi_xml, html5lib, json_loads, nqueens, pathlib, pickle, pickle_dict, pickle_list, pidigits, regex_dna, sqlglot_normalize, sqlglot_parse, sqlglot_transpile, sqlite_synth, sympy_integrate, unpickle_list, xml_etree_generate\n\n\n\u003c/details\u003e \n\nIt doesn't hurt performance, but can decrease number of objects in GC to check and untrack.\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-139390\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sergey-miryanov","@type":"Person","name":"sergey-miryanov"},"datePublished":"2025-09-28T07:40:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/139389/cpython/issues/139389"}
| 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:ca2df7ed-4b1f-b302-bfc6-08c77d3d280a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB58:2C3E22:2550B37:308B97B:696B5AD4 |
| html-safe-nonce | 3231e3bc69147ace56ec6896d8740e217870ed7c35606830f25f216573ef636d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjU4OjJDM0UyMjoyNTUwQjM3OjMwOEI5N0I6Njk2QjVBRDQiLCJ2aXNpdG9yX2lkIjoiODE0Mjg3NTk2NjIzMzU5ODY3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d3f4d864fdb22806d8c8748e885b180f458a2a5057ddbe5651c29d32439acd73 |
| hovercard-subject-tag | issue:3461274287 |
| 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/139389/issue_layout |
| twitter:image | https://opengraph.githubassets.com/283993300eb3c4a5ea9348c60b56a6137d515cc0e8104e2db29bcd01470e5288/python/cpython/issues/139389 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/283993300eb3c4a5ea9348c60b56a6137d515cc0e8104e2db29bcd01470e5288/python/cpython/issues/139389 |
| og:image:alt | Feature or enhancement Proposal: When we use PyTuple_Pack all objects already well constructed. If we know that they immutable we can skip tracking it in GC, because GC will untrack them eventually... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sergey-miryanov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width