Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce overhead to handle queries and responses #1184

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/zeroconf/_handlers.py
Original file line number Diff line number Diff line change
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