Skip to content

Commit e6f96cf

Browse files
authored
gh-106751: Optimize SelectSelector.select() for many iteration case (gh-106879)
1 parent 7513e2e commit e6f96cf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Lib/selectors.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,15 @@ def select(self, timeout=None):
314314
r, w, _ = self._select(self._readers, self._writers, [], timeout)
315315
except InterruptedError:
316316
return ready
317-
r = set(r)
318-
w = set(w)
319-
for fd in r | w:
320-
events = 0
321-
if fd in r:
322-
events |= EVENT_READ
323-
if fd in w:
324-
events |= EVENT_WRITE
325-
326-
key = self._fd_to_key.get(fd)
317+
r = frozenset(r)
318+
w = frozenset(w)
319+
rw = r | w
320+
fd_to_key_get = self._fd_to_key.get
321+
for fd in rw:
322+
key = fd_to_key_get(fd)
327323
if key:
324+
events = ((fd in r and EVENT_READ)
325+
| (fd in w and EVENT_WRITE))
328326
ready.append((key, events & key.events))
329327
return ready
330328

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Optimize :meth:`SelectSelector.select` for many iteration case. Patch By
2+
Dong-hee Na.

0 commit comments

Comments
 (0)