]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735)
authorJ. Nick Koston <nick@koston.org>
Wed, 11 Oct 2023 20:59:27 +0000 (10:59 -1000)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 20:59:27 +0000 (20:59 +0000)
Lib/asyncio/base_events.py
Misc/NEWS.d/next/Library/2023-10-11-18-43-43.gh-issue-110733.UlrgVm.rst [new file with mode: 0644]

index b092c9343634e2db913da3a171fa14285b16353b..956864e4242799ff5a4f09b09c6d042e30c3e262 100644 (file)
@@ -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 (file)
index 0000000..4963e5a
--- /dev/null
@@ -0,0 +1 @@
+Micro-optimization: Avoid calling ``min()``, ``max()`` in :meth:`BaseEventLoop._run_once`.