Decrease event loop latency by binding time.monotonic to loop.time directly (#98288)
* Decrease event loop latency by binding time.monotonic to loop.time directly This is a small improvment to decrease event loop latency. While the goal is is to reduce Bluetooth connection time latency, everything using asyncio is a bit more responsive as a result. * relo per comments * fix too fast by adding resolution, ensure monotonic time is patchable by freezegun * fix test that freezes time too late and has a race loop
This commit is contained in:
@@ -420,6 +420,9 @@ def async_fire_time_changed(
|
||||
_async_fire_time_changed(hass, utc_datetime, fire_all)
|
||||
|
||||
|
||||
_MONOTONIC_RESOLUTION = time.get_clock_info("monotonic").resolution
|
||||
|
||||
|
||||
@callback
|
||||
def _async_fire_time_changed(
|
||||
hass: HomeAssistant, utc_datetime: datetime | None, fire_all: bool
|
||||
@@ -432,7 +435,7 @@ def _async_fire_time_changed(
|
||||
continue
|
||||
|
||||
mock_seconds_into_future = timestamp - time.time()
|
||||
future_seconds = task.when() - hass.loop.time()
|
||||
future_seconds = task.when() - (hass.loop.time() + _MONOTONIC_RESOLUTION)
|
||||
|
||||
if fire_all or mock_seconds_into_future >= future_seconds:
|
||||
with patch(
|
||||
|
||||
Reference in New Issue
Block a user