feat: speed up RecordManager with additional cython defs (#1242) · python-zeroconf/python-zeroconf@5a76fc5
@@ -33,6 +33,8 @@
3333if TYPE_CHECKING:
3434from .._core import Zeroconf
353536+_float = float
37+36383739class RecordManager:
3840"""Process records into the cache and notify listeners."""
@@ -45,7 +47,7 @@ def __init__(self, zeroconf: 'Zeroconf') -> None:
4547self.cache = zeroconf.cache
4648self.listeners: List[RecordUpdateListener] = []
474948-def async_updates(self, now: float, records: List[RecordUpdate]) -> None:
50+def async_updates(self, now: _float, records: List[RecordUpdate]) -> None:
4951"""Used to notify listeners of new information that has updated
5052 a record.
5153@@ -81,6 +83,7 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
8183other_adds: List[DNSRecord] = []
8284removes: Set[DNSRecord] = set()
8385now = msg.now
86+now_float = now
8487unique_types: Set[Tuple[str, int, int]] = set()
8588cache = self.cache
8689@@ -108,11 +111,11 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
108111record = cast(_UniqueRecordsType, record)
109112110113maybe_entry = cache.async_get_unique(record)
111-if not record.is_expired(now):
114+if not record.is_expired(now_float):
112115if maybe_entry is not None:
113116maybe_entry.reset_ttl(record)
114117else:
115-if record.type in _ADDRESS_RECORD_TYPES:
118+if record_type in _ADDRESS_RECORD_TYPES:
116119address_adds.append(record)
117120else:
118121other_adds.append(record)
@@ -146,7 +149,8 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
146149new = False
147150if other_adds or address_adds:
148151new = cache.async_add_records(address_adds)
149-new |= cache.async_add_records(other_adds)
152+if cache.async_add_records(other_adds):
153+new = True
150154# Removes are processed last since
151155# ServiceInfo could generate an un-needed query
152156# because the data was not yet populated.