-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport optimize _run_once for many iterations of the event loop (#242)
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
python/3.11/gh-110733-Optimize-_run_once-for-many-iterations-of-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
From 86a112f61954dede0a777544e59068c0b01c8439 Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <[email protected]> | ||
Date: Wed, 11 Oct 2023 08:34:01 -1000 | ||
Subject: [PATCH] gh-110733: Optimize _run_once for many iterations of the | ||
event loop | ||
|
||
--- | ||
Lib/asyncio/base_events.py | 7 +++++-- | ||
1 file changed, 5 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py | ||
index b092c93436..956864e424 100644 | ||
--- a/Lib/asyncio/base_events.py | ||
+++ b/Lib/asyncio/base_events.py | ||
@@ -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) | ||
-- | ||
2.39.3 (Apple Git-145) | ||
|
31 changes: 31 additions & 0 deletions
31
python/3.12/gh-110733-Optimize-_run_once-for-many-iterations-of-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
From 86a112f61954dede0a777544e59068c0b01c8439 Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <[email protected]> | ||
Date: Wed, 11 Oct 2023 08:34:01 -1000 | ||
Subject: [PATCH] gh-110733: Optimize _run_once for many iterations of the | ||
event loop | ||
|
||
--- | ||
Lib/asyncio/base_events.py | 7 +++++-- | ||
1 file changed, 5 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py | ||
index b092c93436..956864e424 100644 | ||
--- a/Lib/asyncio/base_events.py | ||
+++ b/Lib/asyncio/base_events.py | ||
@@ -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) | ||
-- | ||
2.39.3 (Apple Git-145) | ||
|