Skip to content

Commit

Permalink
feat: improve incoming data processing performance (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jul 8, 2023
1 parent 84872bf commit a56c776
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/zeroconf/_core.py
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
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
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
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

0 comments on commit a56c776

Please sign in to comment.