Title: Use pystats for free threading performance statistics · Issue #131253 · python/cpython · GitHub
Open Graph Title: Use pystats for free threading performance statistics · Issue #131253 · python/cpython
X Title: Use pystats for free threading performance statistics · Issue #131253 · python/cpython
Description: Feature or enhancement It'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already have infrastructure to record Python statistics...
Open Graph Description: Feature or enhancement It'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already have in...
X Description: Feature or enhancement It'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already hav...
Opengraph URL: https://github.com/python/cpython/issues/131253
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use pystats for free threading performance statistics","articleBody":"# Feature or enhancement\n\nIt'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already have infrastructure to record Python statistics in [pystats.h](https://github.com/python/cpython/blob/main/Include/cpython/pystats.h). It'd be great to extend this.\n\nI think there are a few steps needed to support this:\n\n1) pystats should be thread-safe in the free threading build and not inhibit multithreaded scaling. In practice, I think this means that stats should be recorded per-thread and aggregated when a thread exits (and possibly aggregated more often as well).\n\n2) Some stats are cheap to collect and widely useful, including the above mentioned lock contention and some GC stats. We should consider recording some stats even when Python isn't built with `--enable-pystats` so that they are available in release builds, while being careful not to regress performance.\n\n3) Consider providing a Python API for retrieving stats in addition to the existing behavior of dumping stat counters to a file. We don't have to pursue this immediately, but I think it'd be useful in the same ways that `gc.get_stats()` is useful.\n\nFree threading stats:\n\n* Lock contention counter (number of times a thread blocks on a lock acquisition)\n* Stop the world counter (and possibly total duration)\n\ncc @nascheme @zooba @mdboom \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-137189\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2025-03-14T16:30:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/131253/cpython/issues/131253"}
| 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:dea46e5e-4650-328f-5360-e961f6cc80d0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A434:797A1:46E1FF1:5EF402F:6A654785 |
| html-safe-nonce | 8b19e71485b9e21401be3a16b494cbe82fa5abd4d3bdb517134d99927fa2b41a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDM0Ojc5N0ExOjQ2RTFGRjE6NUVGNDAyRjo2QTY1NDc4NSIsInZpc2l0b3JfaWQiOiI1NjAwNjk1OTA0NzYzMjAxNDEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2c9413c378df18e450ca8166cf8e672ecaa2cb9556ac8085b14ad6d064ab47e5 |
| hovercard-subject-tag | issue:2920720258 |
| 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/131253/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b0f9f490ea09ff550526c2b52ed3eab953ba6baa53844a7558d83467c1bd3bb4/python/cpython/issues/131253 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b0f9f490ea09ff550526c2b52ed3eab953ba6baa53844a7558d83467c1bd3bb4/python/cpython/issues/131253 |
| og:image:alt | Feature or enhancement It'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already have in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | colesbury |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b |
| 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 | 309153364422b3c499922d1a2a6404910a58ed8e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width