Skip to content

gh-106751: Optimize KqueueSelector.select() for many iteration case - #106864

Merged
corona10 merged 2 commits into
python:mainfrom
corona10:gh-106754
Jul 19, 2023
Merged

gh-106751: Optimize KqueueSelector.select() for many iteration case#106864
corona10 merged 2 commits into
python:mainfrom
corona10:gh-106754

Conversation

@corona10

@corona10corona10 commented Jul 18, 2023

Copy link
Copy Markdown
Member

@corona10
corona10 requested a review from methaneJuly 18, 2023 13:57
@corona10corona10 changed the title gh-106754: Optimize kqueue selector of the event loopgh-106751: Optimize kqueue selector of the event loopJul 18, 2023
@corona10

corona10 commented Jul 18, 2023

Copy link
Copy Markdown
MemberAuthor

Similar technique can be adopted.

Benchmark

importtimeitimportosfromselectorsimportKqueueSelector, EVENT_WRITE, EVENT_READkqueue=KqueueSelector()
for_inrange(100):
r, w=os.pipe()
os.write(w, b"a")
kqueue.register(r, EVENT_READ)
elapsed=timeit.timeit(
"selector.select()",
number=100000,
globals={"selector": kqueue},
)
print(f"elapsed: {elapsed}")

Result

AS-IS: elapsed -> 2.3957692080002744
TO-BE: elapsed -> 2.2462058329983847 (1.06x faster)

@corona10corona10 added skip news performance Performance or resource usage labels Jul 18, 2023
@corona10corona10 changed the title gh-106751: Optimize kqueue selector of the event loopgh-106751: Optimize kqueue.select()Jul 18, 2023
@corona10corona10 changed the title gh-106751: Optimize kqueue.select()gh-106751: Optimize kqueue.select() for many iterationJul 18, 2023
@corona10corona10 changed the title gh-106751: Optimize kqueue.select() for many iterationgh-106751: Optimize KqueueSelector.select() for many iterationJul 18, 2023
@corona10corona10 changed the title gh-106751: Optimize KqueueSelector.select() for many iterationgh-106751: Optimize KqueueSelector.select() for many iteration caseJul 18, 2023

@eendebakpteendebakpt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor suggestion. Otherwise looks good.

Comment threadLib/selectors.py Outdated
Comment threadLib/selectors.py Outdated
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@bdraco

Copy link
Copy Markdown
Contributor

Awesome. Thanks for picking up the other ones!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performancePerformance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@corona10@bdraco@methane@eendebakpt@bedevere-bot