8000 gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735) · python/cpython@3ac8e69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ac8e69

Browse files
authored
gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735)
1 parent 41d8ec5 commit 3ac8e69

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/asyncio/base_events.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,8 +1907,11 @@ def _run_once(self):
19071907
timeout = 0
19081908
elif self._scheduled:
19091909
# Compute the desired timeout.
1910-
when = self._scheduled[0]._when
1911-
timeout = min(max(0, when - self.time()), MAXIMUM_SELECT_TIMEOUT)
1910+
timeout = self._scheduled[0]._when - self.time()
1911+
if timeout > MAXIMUM_SELECT_TIMEOUT:
1912+
timeout = MAXIMUM_SELECT_TIMEOUT
1913+
elif timeout < 0:
1914+
timeout = 0
19121915

19131916
event_list = self._selector.select(timeout)
19141917
self._process_events(event_list)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Micro-optimization: Avoid calling ``min()``, ``max()`` in :meth:`BaseEventLoop._run_once`.

0 commit comments

Comments
 (0)
0