mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 05:06:13 +01:00
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:
@@ -2,8 +2,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from homeassistant import util
|
||||
from homeassistant import runner, util
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
|
||||
@@ -12,5 +13,11 @@ def _utcnow() -> datetime.datetime:
|
||||
return datetime.datetime.now(datetime.UTC)
|
||||
|
||||
|
||||
def _monotonic() -> float:
|
||||
"""Make monotonic patchable by freezegun."""
|
||||
return time.monotonic()
|
||||
|
||||
|
||||
dt_util.utcnow = _utcnow # type: ignore[assignment]
|
||||
util.utcnow = _utcnow # type: ignore[assignment]
|
||||
runner.monotonic = _monotonic # type: ignore[assignment]
|
||||
|
||||
Reference in New Issue
Block a user