Skip to content

Commit

Permalink
pythongh-110733: Micro-optimization in BaseEventLoop._run_once (pytho…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 11, 2023
1 parent 41d8ec5 commit 3ac8e69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,8 +1907,11 @@ def _run_once(self):
timeout = 0
elif self._scheduled:
# Compute the desired timeout.
when = self._scheduled[0]._when
timeout = min(max(0, when - self.time()), MAXIMUM_SELECT_TIMEOUT)
timeout = self._scheduled[0]._when - self.time()
if timeout > MAXIMUM_SELECT_TIMEOUT:
timeout = MAXIMUM_SELECT_TIMEOUT
elif timeout < 0:
timeout = 0

event_list = self._selector.select(timeout)
self._process_events(event_list)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Micro-optimization: Avoid calling ``min()``, ``max()`` in :meth:`BaseEventLoop._run_once`.

0 comments on commit 3ac8e69

Please sign in to comment.