feat: reduce overhead to handle queries and responses by bdraco · Pull Request #1184 · python-zeroconf/python-zeroconf

Expand Up @@ -124,9 +124,25 @@ def _add_answers_additionals(out: DNSOutgoing, answers: _AnswerWithAdditionalsTy class _QueryResponse: """A pair for unicast and multicast DNSOutgoing responses."""
__slots__ = ( "_is_probe", "_msg", "_now", "_cache", "_additionals", "_ucast", "_mcast_now", "_mcast_aggregate", "_mcast_aggregate_last_second", )
def __init__(self, cache: DNSCache, msgs: List[DNSIncoming]) -> None: """Build a query response.""" self._is_probe = any(msg.is_probe for msg in msgs) self._is_probe = False for msg in msgs: if msg.is_probe: self._is_probe = True break self._msg = msgs[0] self._now = self._msg.now self._cache = cache Expand Down Expand Up @@ -212,6 +228,8 @@ def _has_mcast_record_in_last_second(self, record: DNSRecord) -> bool: class QueryHandler: """Query the ServiceRegistry."""
__slots__ = ("registry", "cache", "question_history")
def __init__(self, registry: ServiceRegistry, cache: DNSCache, question_history: QuestionHistory) -> None: """Init the query handler.""" self.registry = registry Expand Down Expand Up @@ -345,6 +363,8 @@ def async_response( # pylint: disable=unused-argument class RecordManager: """Process records into the cache and notify listeners."""
__slots__ = ("zc", "cache", "listeners")
def __init__(self, zeroconf: 'Zeroconf') -> None: """Init the record manager.""" self.zc = zeroconf Expand Down Expand Up @@ -516,6 +536,8 @@ def async_remove_listener(self, listener: RecordUpdateListener) -> None: class MulticastOutgoingQueue: """An outgoing queue used to aggregate multicast responses."""
__slots__ = ("zc", "queue", "additional_delay", "aggregation_delay")
def __init__(self, zeroconf: 'Zeroconf', additional_delay: int, max_aggregation_delay: int) -> None: self.zc = zeroconf self.queue: deque = deque() Expand Down