René's URL Explorer Experiment


Title: Optimize XXXSelector for many iterations of the event loop · Issue #106751 · python/cpython · GitHub

Open Graph Title: Optimize XXXSelector for many iterations of the event loop · Issue #106751 · python/cpython

X Title: Optimize XXXSelector for many iterations of the event loop · Issue #106751 · python/cpython

Description: split out from #106555 (comment) The current EpollSelector can be sped up a bit. This makes quite a difference when there are 100000+ iterations of the event loop per minute (the use case being receiving bluetooth data from multiple sour...

Open Graph Description: split out from #106555 (comment) The current EpollSelector can be sped up a bit. This makes quite a difference when there are 100000+ iterations of the event loop per minute (the use case being rec...

X Description: split out from #106555 (comment) The current EpollSelector can be sped up a bit. This makes quite a difference when there are 100000+ iterations of the event loop per minute (the use case being rec...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optimize XXXSelector for many iterations of the event loop","articleBody":"split out from https://github.com/python/cpython/pull/106555#issuecomment-1632025959\r\n\r\nThe current `EpollSelector` can be sped up a bit. This makes quite a difference when there are 100000+ iterations of the event loop per minute (the use case being receiving bluetooth data from multiple sources) since selectors have to run every iteration.\r\n\r\noriginal: 11.831302762031555\r\nnew: 9.579423972172663\r\n\r\n```\r\nimport timeit\r\nimport math\r\nimport select\r\nimport os\r\nfrom selectors import EpollSelector, EVENT_WRITE, EVENT_READ\r\n\r\n\r\nclass OriginalEpollSelector(EpollSelector):\r\n    def select(self, timeout=None):\r\n        if timeout is None:\r\n            timeout = -1\r\n        elif timeout \u003c= 0:\r\n            timeout = 0\r\n        else:\r\n            # epoll_wait() has a resolution of 1 millisecond, round away\r\n            # from zero to wait *at least* timeout seconds.\r\n            timeout = math.ceil(timeout * 1e3) * 1e-3\r\n        # epoll_wait() expects `maxevents` to be greater than zero;\r\n        # we want to make sure that `select()` can be called when no\r\n        # FD is registered.\r\n        max_ev = max(len(self._fd_to_key), 1)\r\n        ready = []\r\n        try:\r\n            fd_event_list = self._selector.poll(timeout, max_ev)\r\n        except InterruptedError:\r\n            return ready\r\n        for fd, event in fd_event_list:\r\n            events = 0\r\n            if event \u0026 ~select.EPOLLIN:\r\n                events |= EVENT_WRITE\r\n            if event \u0026 ~select.EPOLLOUT:\r\n                events |= EVENT_READ\r\n\r\n            key = self._key_from_fd(fd)\r\n            if key:\r\n                ready.append((key, events \u0026 key.events))\r\n        return ready\r\n\r\n\r\nNOT_EPOLLIN = ~select.EPOLLIN\r\nNOT_EPOLLOUT = ~select.EPOLLOUT\r\n\r\nclass NewEpollSelector(EpollSelector):\r\n    def select(self, timeout=None):\r\n        if timeout is None:\r\n            timeout = -1\r\n        elif timeout \u003c= 0:\r\n            timeout = 0\r\n        else:\r\n            # epoll_wait() has a resolution of 1 millisecond, round away\r\n            # from zero to wait *at least* timeout seconds.\r\n            timeout = math.ceil(timeout * 1e3) * 1e-3\r\n        # epoll_wait() expects `maxevents` to be greater than zero;\r\n        # we want to make sure that `select()` can be called when no\r\n        # FD is registered.\r\n        max_ev = len(self._fd_to_key) or 1\r\n        ready = []\r\n        try:\r\n            fd_event_list = self._selector.poll(timeout, max_ev)\r\n        except InterruptedError:\r\n            return ready\r\n        \r\n        fd_to_key = self._fd_to_key\r\n        for fd, event in fd_event_list:\r\n            key = fd_to_key.get(fd)\r\n            if key:\r\n                ready.append(\r\n                    (\r\n                        key,\r\n                        (\r\n                            (event \u0026 NOT_EPOLLIN and EVENT_WRITE)\r\n                            | (event \u0026 NOT_EPOLLOUT and EVENT_READ)\r\n                        )\r\n                        \u0026 key.events,\r\n                    )\r\n                )\r\n        return ready\r\n\r\n\r\noriginal_epoll = OriginalEpollSelector()\r\nnew_epoll = NewEpollSelector()\r\n\r\n\r\nfor _ in range(512):\r\n    r, w = os.pipe()\r\n    os.write(w, b\"a\")\r\n    original_epoll.register(r, EVENT_READ)\r\n    new_epoll.register(r, EVENT_READ)\r\n\r\n\r\noriginal_time = timeit.timeit(\r\n    \"selector.select()\",\r\n    number=100000,\r\n    globals={\"selector\": original_epoll},\r\n)\r\nnew_time = timeit.timeit(\r\n    \"selector.select()\",\r\n    number=100000,\r\n    globals={\"selector\": new_epoll},\r\n)\r\n\r\nprint(\"original: %s\" % original_time)\r\nprint(\"new: %s\" % new_time)\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-106754\n* gh-106864\n* gh-106879\n* gh-106884\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/bdraco","@type":"Person","name":"bdraco"},"datePublished":"2023-07-14T19:48:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/106751/cpython/issues/106751"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:edebf4d2-e274-d5a4-8098-81c6d041cbb7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8B14:E8423:12B01B1:190BB6D:696AD608
html-safe-nonce564f7bcf96e6647a42e45c5fcc066f81582dc3bf0d4513e6c9990910b0e153d0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjE0OkU4NDIzOjEyQjAxQjE6MTkwQkI2RDo2OTZBRDYwOCIsInZpc2l0b3JfaWQiOiIxMTg3ODgxMTQwMDA1NTU3NzY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf7f10db535abb5e28038d8636a85be5936b5c6064eed85a5b5a0410049f3b08d
hovercard-subject-tagissue:1805459731
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/106751/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d835696a7c35a695746b466efc84652cb732e86b66b15444a370c3051aedd3cc/python/cpython/issues/106751
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d835696a7c35a695746b466efc84652cb732e86b66b15444a370c3051aedd3cc/python/cpython/issues/106751
og:image:altsplit out from #106555 (comment) The current EpollSelector can be sped up a bit. This makes quite a difference when there are 100000+ iterations of the event loop per minute (the use case being rec...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebdraco
hostnamegithub.com
expected-hostnamegithub.com
Nonec785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d
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
releasec718a376fcf780eb22089171adb84a543f660bf7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/106751#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F106751
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%2F106751
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/106751
Reloadhttps://github.com/python/cpython/issues/106751
Reloadhttps://github.com/python/cpython/issues/106751
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/106751
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/106751
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/106751
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/106751
#106879https://github.com/python/cpython/pull/106879
Optimize XXXSelector for many iterations of the event loophttps://github.com/python/cpython/issues/106751#top
#106879https://github.com/python/cpython/pull/106879
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
https://github.com/bdraco
https://github.com/bdraco
bdracohttps://github.com/bdraco
on Jul 14, 2023https://github.com/python/cpython/issues/106751#issue-1805459731
#106555 (comment)https://github.com/python/cpython/pull/106555#issuecomment-1632025959
gh-106751: selectors: optimize EpollSelector.select() #106754https://github.com/python/cpython/pull/106754
gh-106751: Optimize KqueueSelector.select() for many iteration case #106864https://github.com/python/cpython/pull/106864
gh-106751: Optimize SelectSelector.select() for many iteration case #106879https://github.com/python/cpython/pull/106879
gh-106751: Optimize _PolllikeSelector for many iteration case #106884https://github.com/python/cpython/pull/106884
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
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.