René's URL Explorer Experiment


Title: Reduce asyncio heapq overhead · Issue #122881 · python/cpython · GitHub

Open Graph Title: Reduce asyncio heapq overhead · Issue #122881 · python/cpython

X Title: Reduce asyncio heapq overhead · Issue #122881 · python/cpython

Description: Feature or enhancement Proposal: The heapq calls in base_events.py represents quite a bit of asyncio scheduling overhead because they have to run __lt__ quite often in TimerHandle cpython/Lib/asyncio/events.py Line 128 in 0fd97e4 def __l...

Open Graph Description: Feature or enhancement Proposal: The heapq calls in base_events.py represents quite a bit of asyncio scheduling overhead because they have to run __lt__ quite often in TimerHandle cpython/Lib/async...

X Description: Feature or enhancement Proposal: The heapq calls in base_events.py represents quite a bit of asyncio scheduling overhead because they have to run __lt__ quite often in TimerHandle cpython/Lib/async...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reduce asyncio heapq overhead","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\nThe `heapq` calls in base_events.py represents quite a bit of asyncio scheduling overhead because they have to run `__lt__` quite often in `TimerHandle` https://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/events.py#L128\r\n\r\nhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L1968\r\n![heapify](https://github.com/user-attachments/assets/f91833d3-3c7b-45fe-9fde-012fce8684c6)\r\n\r\nhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L815\r\n![heappush](https://github.com/user-attachments/assets/762df6a1-ddf4-4e85-8987-71ece0cc49c4)\r\n\r\n\r\nhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L1975\r\n![heappop](https://github.com/user-attachments/assets/13951125-990c-4709-828d-494e5bf9337e)\r\n\r\n\r\nAvoiding running `__lt__` can speed up processing `call_at`s by ~10%\r\n\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nThis is a minor feature, which does not need previous discussion elsewhere\r\n\r\n### Links to previous discussion of this feature:\r\n\r\nWrapping `TimerHandle` in a tuple starting with `when` avoids the `__lt__` call.  Thank you to whoever wrote the `heapq` docs for help getting there https://docs.python.org/3/library/heapq.html#basic-examples \r\n6f80b4c8b7be\r\n\r\n\r\nExample benchmark\r\n```python\r\nfrom asyncio import TimerHandle\r\nimport heapq\r\nimport timeit\r\n\r\n\r\ndef callback():\r\n    \"\"\"This is the callback function that will be called when the timer expires.\"\"\"\r\n\r\n\r\nclass MockLoop:\r\n    def get_debug(self):\r\n        return False\r\n\r\n\r\nloop = MockLoop()\r\n\r\n\r\ndef heap_tuple():\r\n    scheduled = []\r\n    when = 1\r\n\r\n    for _ in range(100):\r\n        when += 1\r\n        handle = TimerHandle(when, callback, (), loop)\r\n        heapq.heappush(scheduled, (when, handle))\r\n\r\n    while scheduled:\r\n        when, handle = heapq.heappop(scheduled)\r\n\r\n\r\ndef heap_handle():\r\n    scheduled = []\r\n    when = 1\r\n\r\n    for _ in range(100):\r\n        when += 1\r\n        handle = TimerHandle(when, callback, (), loop)\r\n        heapq.heappush(scheduled, handle)\r\n\r\n    while scheduled:\r\n        handle = heapq.heappop(scheduled)\r\n\r\n\r\nprint(\"wrap when, TimerHandle in tuple\", timeit.timeit(heap_tuple))\r\nprint(\"bare TimerHandle\", timeit.timeit(heap_handle))\r\n```\r\n\r\n```\r\n% python3 bench/timer_handle_heap.py\r\nwrap when, TimerHandle in tuple 34.082984749999014\r\nbare TimerHandle 49.678519583001616\r\n```\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-122882\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/bdraco","@type":"Person","name":"bdraco"},"datePublished":"2024-08-10T12:58:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/122881/cpython/issues/122881"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f55a4218-8605-2b8e-f4d6-221df60ddbdb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idACD2:E3F0D:200AF19:29B0B07:696B473A
html-safe-noncebd68fad55957289280360d415ecfd18e767f8dae16c2cbd1ece1089eb2f04cab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0QyOkUzRjBEOjIwMEFGMTk6MjlCMEIwNzo2OTZCNDczQSIsInZpc2l0b3JfaWQiOiIyMDMxOTM5NzgyNDQxNjQ5OTc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac02f23efd0e43479f8af9189fc19d6b85d2dbaf419ffe224a318167cc986bbfbd
hovercard-subject-tagissue:2459074533
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/122881/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2b42594401b9779a6592e845d481480fae061497153d1c872b08d8f0e3a2bdde/python/cpython/issues/122881
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2b42594401b9779a6592e845d481480fae061497153d1c872b08d8f0e3a2bdde/python/cpython/issues/122881
og:image:altFeature or enhancement Proposal: The heapq calls in base_events.py represents quite a bit of asyncio scheduling overhead because they have to run __lt__ quite often in TimerHandle cpython/Lib/async...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebdraco
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
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
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/122881#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F122881
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
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
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
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/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%2F122881
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/122881
Reloadhttps://github.com/python/cpython/issues/122881
Reloadhttps://github.com/python/cpython/issues/122881
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/122881
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k 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.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/122881
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 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/122881
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/122881
Reduce asyncio heapq overheadhttps://github.com/python/cpython/issues/122881#top
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/bdraco
https://github.com/bdraco
bdracohttps://github.com/bdraco
on Aug 10, 2024https://github.com/python/cpython/issues/122881#issue-2459074533
cpython/Lib/asyncio/events.pyhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/events.py#L128
0fd97e4https://github.com/python/cpython/commit/0fd97e46c75bb3060485b796ca597b13af7e6bec
cpython/Lib/asyncio/base_events.pyhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L1968
0fd97e4https://github.com/python/cpython/commit/0fd97e46c75bb3060485b796ca597b13af7e6bec
https://private-user-images.githubusercontent.com/663432/356812527-f91833d3-3c7b-45fe-9fde-012fce8684c6.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg2Mzg1NjYsIm5iZiI6MTc2ODYzODI2NiwicGF0aCI6Ii82NjM0MzIvMzU2ODEyNTI3LWY5MTgzM2QzLTNjN2ItNDVmZS05ZmRlLTAxMmZjZTg2ODRjNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDExN1QwODI0MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kOGNlZDk5NmM0NzM4N2I5ZjA3ODgyNjNhNWI2Y2JkNzQ1YzlkNmE1MWNiMDI1ZmQ5ZWRjNGI5NWQ2MDc0OThiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.XtZUJSOygq5n1hfkNeYpcEU4NMMNYgQnhbWEg5lVcN4
cpython/Lib/asyncio/base_events.pyhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L815
0fd97e4https://github.com/python/cpython/commit/0fd97e46c75bb3060485b796ca597b13af7e6bec
https://private-user-images.githubusercontent.com/663432/356812535-762df6a1-ddf4-4e85-8987-71ece0cc49c4.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg2Mzg1NjYsIm5iZiI6MTc2ODYzODI2NiwicGF0aCI6Ii82NjM0MzIvMzU2ODEyNTM1LTc2MmRmNmExLWRkZjQtNGU4NS04OTg3LTcxZWNlMGNjNDljNC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDExN1QwODI0MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mYzIyMGYzNjVhN2U0ZTY1ZTkyOGE1ZThkZTBlNDM1ZTk3ZWJjODU2ZjQyNDVmNmQ1MDc3MGM3ZGFhZWMzZTkxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9._pvn7i5B6u4quEU1FGTQS_Jw-qMOESF4HvHFHFEEqCs
cpython/Lib/asyncio/base_events.pyhttps://github.com/python/cpython/blob/0fd97e46c75bb3060485b796ca597b13af7e6bec/Lib/asyncio/base_events.py#L1975
0fd97e4https://github.com/python/cpython/commit/0fd97e46c75bb3060485b796ca597b13af7e6bec
https://private-user-images.githubusercontent.com/663432/356812541-13951125-990c-4709-828d-494e5bf9337e.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg2Mzg1NjYsIm5iZiI6MTc2ODYzODI2NiwicGF0aCI6Ii82NjM0MzIvMzU2ODEyNTQxLTEzOTUxMTI1LTk5MGMtNDcwOS04MjhkLTQ5NGU1YmY5MzM3ZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDExN1QwODI0MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wNzc1OTYzNTE0ZWNmMDJjZmZjZTk4MGY1Y2E2MGVlYTY1ZGFjYWEzY2Y2OTczODkxMTFhMzQwZmJlNjQ5ZTY3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Ef3SUHUj9at-c4Teg9E28l6a4Jbc_BrlR-azPeRqGN8
https://docs.python.org/3/library/heapq.html#basic-exampleshttps://docs.python.org/3/library/heapq.html#basic-examples
6f80b4chttps://github.com/python/cpython/commit/6f80b4c8b7be1277f91fc7e923b200b83bc4ad88
gh-122881: Reduce asyncio heapq scheduling overhead #122882https://github.com/python/cpython/pull/122882
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
asynciohttps://github.com/orgs/python/projects/29
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.