From 3ac8e6955fedc35e8646bee7e04be6f20205cc1e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Oct 2023 10:59:27 -1000 Subject: gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735) --- Lib/asyncio/base_events.py | 7 +++++-- .../next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index b092c93..956864e 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1907,8 +1907,11 @@ class BaseEventLoop(events.AbstractEventLoop): 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) diff --git a/Misc/NEWS.d/next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst b/Misc/NEWS.d/next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst new file mode 100644 index 0000000..4963e5a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst @@ -0,0 +1 @@ +Micro-optimization: Avoid calling ``min()``, ``max()`` in :meth:`BaseEventLoop._run_once`. -- cgit v0.12