René's URL Explorer Experiment


Title: gh-159137: `gc`: Count GC survivors in `untrack_tuples()` instead of walking the young generation again by maurycy · Pull Request #159149 · python/cpython · GitHub

Open Graph Title: gh-159137: `gc`: Count GC survivors in `untrack_tuples()` instead of walking the young generation again by maurycy · Pull Request #159149 · python/cpython

X Title: gh-159137: `gc`: Count GC survivors in `untrack_tuples()` instead of walking the young generation again by maurycy · Pull Request #159149 · python/cpython

Description: Inspired by #159137. After deduce_unreachable(), gc_collect_main() walks the surviving young generation twice. untrack_tuples() visits every object: cpython/Python/gc.c Lines 664 to 676 in 9028df3 static void untrack_tuples(PyGC_Head *head) { PyGC_Head *gc = GC_NEXT(head); while (gc != head) { PyObject *op = FROM_GC(gc); PyGC_Head *next = GC_NEXT(gc); if (PyTuple_CheckExact(op)) { _PyTuple_MaybeUntrack(op); } gc = next; } } and then gc_list_size(young) walks the same list again only to update long_lived_pending or long_lived_total: cpython/Python/gc.c Lines 1517 to 1535 in 9028df3 untrack_tuples(young); /* Move reachable objects to next generation. */ if (young != old) { if (generation == NUM_GENERATIONS - 2) { gcstate->long_lived_pending += gc_list_size(young); } gc_list_merge(young, old); } else { // In Python <= 3.13, we called untrack_dicts(young) here to untrack // atomic-only dicts (see issue #14775). Python 3.14 removed the lazy // dict tracking machinery entirely (GH-127010) -- dicts are always // tracked from creation and never untracked by GC. That way, we don't // have to restore MAINTAIN_TRACKING across every PyDict_SetItem call // site; the cost is slightly more work for full collections on dicts // with only atomic values. gcstate->long_lived_pending = 0; gcstate->long_lived_total = gc_list_size(young); } So the idea is to untrack_tuples() to return the number of objects that stay tracked, and use it instead of gc_list_size(young). Microbenchmark Full collections on a heap that stays alive for the whole run. macOS 27 (M4 Air), release build w/o PGO. Median of 6 processes per binary, interleaved A/B/B/A: heap main (9028df3) 9028df3 + patch 2M objects, dict + list + tuple per entry 77.0 ms 67.4 ms -12% 2M dicts with atomic values 66.9 ms 59.0 ms -12% 5M objects, dict + list + tuple per entry 201.7 ms 169.6 ms -16% 2M tuples of ints 11.6 ms 11.6 ms 0% Unfortunately, I don't have access to Linux baremetal at the moment. Macrobenchmark Sphinx 8.2.3 building the CPython HTML docs with one worker and fresh doctrees (sphinx-build -b html -j 1 -E), same machine and builds, 6 runs per binary interleaved A/B/B/A. GC time is the sum of duration from gc.get_stats() main (9028df3) 9028df3 + patch CPU time 46.00 s 44.37 s -3.5% GC time 10.07 s 8.63 s -14% GC time, full collections only 8.66 s 7.26 s -16% CPU time outside GC 35.93 s 35.74 s -0.5% Microbenchmark import gc, sys, time N = int(sys.argv[1]); kind = sys.argv[2] gc.disable() if kind == "mixed": keep = [({"a": i, "b": None}, [i, i], (i, i + 1)) for i in range(N // 3)] elif kind == "tuples": keep = [(i, i + 1, i + 2) for i in range(N)] elif kind == "dicts": keep = [{"a": i, "b": "x"} for i in range(N)] for _ in range(2): gc.collect() ts = [] for _ in range(7): t0 = time.perf_counter_ns(); gc.collect(); ts.append(time.perf_counter_ns() - t0) ts.sort(); print(ts[3] / 1e6) Issue: gh-159137

Open Graph Description: Inspired by #159137. After deduce_unreachable(), gc_collect_main() walks the surviving young generation twice. untrack_tuples() visits every object: cpython/Python/gc.c ...

X Description: Inspired by #159137. After deduce_unreachable(), gc_collect_main() walks the surviving young generation twice. untrack_tuples() visits every object: cpython/Python/gc.c ...

Opengraph URL: https://github.com/python/cpython/pull/159149

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:192f9846-ed52-f6e4-8ff1-8378dde3072e
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC3E6:33444D:33E1101:44FBB1E:6B01FB88
html-safe-nonce86cb89b53ccf664a785c3beffb8d1285e15a988dc8649b120a01b08f1ac697e3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0U2OjMzNDQ0RDozM0UxMTAxOjQ0RkJCMUU6NkIwMUZCODgiLCJ2aXNpdG9yX2lkIjoiNzc2MTU3MDk2NDQ0OTY1NTY4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1c7e1f8920546b22c2a66ae1c688a4051c7053e10207e3b75a89e52740142f43
hovercard-subject-tagpull_request:4814498090
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/159149/files
twitter:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
og:image:altInspired by #159137. After deduce_unreachable(), gc_collect_main() walks the surviving young generation twice. untrack_tuples() visits every object: cpython/Python/gc.c ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
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

Links:

Skip to contenthttps://github.com/python/cpython/pull/159149/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F159149%2Ffiles
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%2Fpull%2F159149%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/159149/files
Reloadhttps://github.com/python/cpython/pull/159149/files
Reloadhttps://github.com/python/cpython/pull/159149/files
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
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
maurycyhttps://github.com/maurycy
python:mainhttps://github.com/python/cpython/tree/main
maurycy:gc-untrack-counthttps://github.com/maurycy/cpython/tree/gc-untrack-count
Conversation 3 https://github.com/python/cpython/pull/159149
Commits 2 https://github.com/python/cpython/pull/159149/commits
Checks 53 https://github.com/python/cpython/pull/159149/checks
Files changed https://github.com/python/cpython/pull/159149/files
Please reload this pagehttps://github.com/python/cpython/pull/159149/files
gh-159137: gc: Count GC survivors in untrack_tuples() instead of walking the young generation again https://github.com/python/cpython/pull/159149/files#top
Show all changes 2 commits https://github.com/python/cpython/pull/159149/files
e3ee67d up maurycy Oct 10, 2026 https://github.com/python/cpython/pull/159149/commits/e3ee67d84efe2b26b6a8be3f084d085704361217
0665b13 news maurycy Oct 10, 2026 https://github.com/python/cpython/pull/159149/commits/0665b13782286b9854ff0de207c463859c159217
Clear filters https://github.com/python/cpython/pull/159149/files
Please reload this pagehttps://github.com/python/cpython/pull/159149/files
Please reload this pagehttps://github.com/python/cpython/pull/159149/files
2026-10-10-23-01-13.gh-issue-159137.kTq3Lw.rst https://github.com/python/cpython/pull/159149/files#diff-61ece6277406cd80c22a56c5f8e966ac1b42eb5b137cd97002b86041a02e081d
gc.c https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
Misc/NEWS.d/next/Core_and_Builtins/2026-10-10-23-01-13.gh-issue-159137.kTq3Lw.rsthttps://github.com/python/cpython/pull/159149/files#diff-61ece6277406cd80c22a56c5f8e966ac1b42eb5b137cd97002b86041a02e081d
View file https://github.com/maurycy/cpython/blob/0665b13782286b9854ff0de207c463859c159217/Misc/NEWS.d/next/Core_and_Builtins/2026-10-10-23-01-13.gh-issue-159137.kTq3Lw.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159149/{{ revealButtonHref }}
Python/gc.chttps://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
View file https://github.com/maurycy/cpython/blob/0665b13782286b9854ff0de207c463859c159217/Python/gc.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159149/{{ revealButtonHref }}
https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
https://github.com/python/cpython/pull/159149/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385
Please reload this pagehttps://github.com/python/cpython/pull/159149/files
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.