From 0d2cdbfcdf648ff070d4c02cf50dddc1643ea81e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 8 Jul 2023 15:48:52 -1000 Subject: [PATCH 1/7] Replace _key_from_fd with a simple get in _BaseSelectorImpl `_key_from_fd` re-implemented `.get()` and can be removed --- Lib/selectors.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/Lib/selectors.py b/Lib/selectors.py index af6a4f94b5008a..7f9aa1ae6032b7 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -272,19 +272,6 @@ def close(self): def get_map(self): return self._map - def _key_from_fd(self, fd): - """Return the key associated to a given file descriptor. - - Parameters: - fd -- file descriptor - - Returns: - corresponding key, or None if not found - """ - try: - return self._fd_to_key[fd] - except KeyError: - return None class SelectSelector(_BaseSelectorImpl): @@ -332,7 +319,7 @@ def select(self, timeout=None): if fd in w: events |= EVENT_WRITE - key = self._key_from_fd(fd) + key = self._fd_to_key.get(fd) if key: ready.append((key, events & key.events)) return ready @@ -422,7 +409,7 @@ def select(self, timeout=None): if event & ~self._EVENT_WRITE: events |= EVENT_READ - key = self._key_from_fd(fd) + key = self._fd_to_key.get(fd) if key: ready.append((key, events & key.events)) return ready @@ -475,7 +462,7 @@ def select(self, timeout=None): if event & ~select.EPOLLOUT: events |= EVENT_READ - key = self._key_from_fd(fd) + key = self._fd_to_key.get(fd) if key: ready.append((key, events & key.events)) return ready @@ -570,7 +557,7 @@ def select(self, timeout=None): if flag == select.KQ_FILTER_WRITE: events |= EVENT_WRITE - key = self._key_from_fd(fd) + key = self._fd_to_key.get(fd) if key: ready.append((key, events & key.events)) return ready From ccff5596a85f508fb7d62a38dd8f3395b0f417d1 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 9 Jul 2023 01:59:26 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst new file mode 100644 index 00000000000000..b7bfefb0ef8978 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -0,0 +1 @@ +Reduce selector overhead From 9ad995be9a180b1e52859366ae4883cd97dbb135 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 12 Jul 2023 07:02:23 -1000 Subject: [PATCH 3/7] Update Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst index b7bfefb0ef8978..6be9b4ce5ddd29 100644 --- a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -1 +1 @@ -Reduce selector overhead +Reduce selector overhead by switching `SelectSelector` to use a `dict` `.get()` for `fd`s From 2921723261e90450feba4484f4c420a885e36c9e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 12 Jul 2023 07:35:08 -1000 Subject: [PATCH 4/7] Update Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst index 6be9b4ce5ddd29..60e4b4af0d932b 100644 --- a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -1 +1 @@ -Reduce selector overhead by switching `SelectSelector` to use a `dict` `.get()` for `fd`s +Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` for ``fd``s From c781753ef4df3a6955315b81d51f3257f1d88017 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 12 Jul 2023 07:36:08 -1000 Subject: [PATCH 5/7] Update 2023-07-09-01-59-24.gh-issue-106554.37c53J.rst --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst index 60e4b4af0d932b..9d77534660791b 100644 --- a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -1 +1 @@ -Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` for ``fd``s +Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` to fetch file descriptors. From 0841b2e61ff75f17ae1e0bbb2b524dae848f4725 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 12 Jul 2023 07:36:34 -1000 Subject: [PATCH 6/7] Update Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst index 9d77534660791b..f3a7d7d62469db 100644 --- a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -1 +1 @@ -Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` to fetch file descriptors. +Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` to lookup file descriptors. From d80ae26980f400352f92521965eed7ad223ead2a Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 15 Jul 2023 02:55:53 +0900 Subject: [PATCH 7/7] Update Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst --- .../next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst index f3a7d7d62469db..2136f3aa5a8eb0 100644 --- a/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst +++ b/Misc/NEWS.d/next/Library/2023-07-09-01-59-24.gh-issue-106554.37c53J.rst @@ -1 +1 @@ -Reduce selector overhead by switching ``SelectSelector`` to use a ``dict`` ``.get()`` to lookup file descriptors. +:mod:`selectors`: Reduce Selector overhead by using a ``dict.get()`` to lookup file descriptors.