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: improve incoming data processing performance #1194

Merged
merged 3 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ def _make_wrapped_transport(transport: asyncio.DatagramTransport) -> _WrappedTra
class AsyncEngine:
"""An engine wraps sockets in the event loop."""

__slots__ = (
'loop',
'zc',
'protocols',
'readers',
'senders',
'running_event',
'_listen_socket',
'_respond_sockets',
'_cleanup_timer',
)

def __init__(
self,
zeroconf: 'Zeroconf',
Expand Down
6 changes: 6 additions & 0 deletions src/zeroconf/_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def update_service(self, zc: 'Zeroconf', type_: str, name: str) -> None:


class Signal:

__slots__ = ('_handlers',)

def __init__(self) -> None:
self._handlers: List[Callable[..., None]] = []

Expand All @@ -59,6 +62,9 @@ def registration_interface(self) -> 'SignalRegistrationInterface':


class SignalRegistrationInterface:

__slots__ = ('_handlers',)

def __init__(self, handlers: List[Callable[..., None]]) -> None:
self._handlers = handlers

Expand Down
22 changes: 21 additions & 1 deletion src/zeroconf/_services/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
class _DNSPointerOutgoingBucket:
"""A DNSOutgoing bucket."""

__slots__ = ('now', 'out', 'bytes')

def __init__(self, now: float, multicast: bool) -> None:
"""Create a bucke to wrap a DNSOutgoing."""
self.now = now
Expand Down Expand Up @@ -196,12 +198,14 @@ class QueryScheduler:

"""

__slots__ = ('_schedule_changed_event', '_types', '_next_time', '_first_random_delay_interval', '_delay')

def __init__(
self,
types: Set[str],
delay: int,
first_random_delay_interval: Tuple[int, int],
):
) -> None:
self._schedule_changed_event: Optional[asyncio.Event] = None
self._types = types
self._next_time: Dict[str, float] = {}
Expand Down Expand Up @@ -261,6 +265,22 @@ def process_ready_types(self, now: float) -> List[str]:
class _ServiceBrowserBase(RecordUpdateListener):
"""Base class for ServiceBrowser."""

__slots__ = (
'types',
'zc',
'addr',
'port',
'multicast',
'question_type',
'_pending_handlers',
'_service_state_changed',
'query_scheduler',
'done',
'_first_request',
'_next_send_timer',
'_query_sender_task',
)

def __init__(
self,
zc: 'Zeroconf',
Expand Down
2 changes: 2 additions & 0 deletions src/zeroconf/_services/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ServiceRegistry:
the event loop as it is not thread safe.
"""

__slots__ = ("_services", "types", "servers")

def __init__(
self,
) -> None:
Expand Down