Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jul 19, 2023

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Jul 18, 2023

@corona10 corona10 requested a review from methane July 18, 2023 13:57
@corona10 corona10 changed the title gh-106754: Optimize kqueue selector of the event loop gh-106751: Optimize kqueue selector of the event loop Jul 18, 2023
@corona10
Copy link
Member Author

corona10 commented Jul 18, 2023

Similar technique can be adopted.

Benchmark

import timeit
import os
from selectors import KqueueSelector, EVENT_WRITE, EVENT_READ

kqueue = KqueueSelector()
for _ in range(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)

@corona10 corona10 added skip news performance Performance or resource usage labels Jul 18, 2023
@corona10 corona10 changed the title gh-106751: Optimize kqueue selector of the event loop gh-106751: Optimize kqueue.select() Jul 18, 2023
@corona10 corona10 changed the title gh-106751: Optimize kqueue.select() gh-106751: Optimize kqueue.select() for many iteration Jul 18, 2023
@corona10 corona10 changed the title gh-106751: Optimize kqueue.select() for many iteration gh-106751: Optimize KqueueSelector.select() for many iteration Jul 18, 2023
@corona10 corona10 changed the title gh-106751: Optimize KqueueSelector.select() for many iteration gh-106751: Optimize KqueueSelector.select() for many iteration case Jul 18, 2023
Copy link
Contributor

@eendebakpt eendebakpt left a comment

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.

Lib/selectors.py Outdated Show resolved Hide resolved
Lib/selectors.py Outdated Show resolved Hide resolved
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@corona10 corona10 merged commit 7513e2e into python:main Jul 19, 2023
22 of 23 checks passed
@bdraco
Copy link
Contributor

bdraco commented Jul 19, 2023

Awesome. Thanks for picking up the other ones!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants