Skip to content

Commit a56c776

Browse files
authored
feat: improve incoming data processing performance (#1194)
1 parent 84872bf commit a56c776

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/zeroconf/_core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ def _make_wrapped_transport(transport: asyncio.DatagramTransport) -> _WrappedTra
151151
class AsyncEngine:
152152
"""An engine wraps sockets in the event loop."""
153153

154+
__slots__ = (
155+
'loop',
156+
'zc',
157+
'protocols',
158+
'readers',
159+
'senders',
160+
'running_event',
161+
'_listen_socket',
162+
'_respond_sockets',
163+
'_cleanup_timer',
164+
)
165+
154166
def __init__(
155167
self,
156168
zeroconf: 'Zeroconf',

src/zeroconf/_services/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def update_service(self, zc: 'Zeroconf', type_: str, name: str) -> None:
4646

4747

4848
class Signal:
49+
50+
__slots__ = ('_handlers',)
51+
4952
def __init__(self) -> None:
5053
self._handlers: List[Callable[..., None]] = []
5154

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

6063

6164
class SignalRegistrationInterface:
65+
66+
__slots__ = ('_handlers',)
67+
6268
def __init__(self, handlers: List[Callable[..., None]]) -> None:
6369
self._handlers = handlers
6470

src/zeroconf/_services/browser.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
class _DNSPointerOutgoingBucket:
8686
"""A DNSOutgoing bucket."""
8787

88+
__slots__ = ('now', 'out', 'bytes')
89+
8890
def __init__(self, now: float, multicast: bool) -> None:
8991
"""Create a bucke to wrap a DNSOutgoing."""
9092
self.now = now
@@ -196,12 +198,14 @@ class QueryScheduler:
196198
197199
"""
198200

201+
__slots__ = ('_schedule_changed_event', '_types', '_next_time', '_first_random_delay_interval', '_delay')
202+
199203
def __init__(
200204
self,
201205
types: Set[str],
202206
delay: int,
203207
first_random_delay_interval: Tuple[int, int],
204-
):
208+
) -> None:
205209
self._schedule_changed_event: Optional[asyncio.Event] = None
206210
self._types = types
207211
self._next_time: Dict[str, float] = {}
@@ -261,6 +265,22 @@ def process_ready_types(self, now: float) -> List[str]:
261265
class _ServiceBrowserBase(RecordUpdateListener):
262266
"""Base class for ServiceBrowser."""
263267

268+
__slots__ = (
269+
'types',
270+
'zc',
271+
'addr',
272+
'port',
273+
'multicast',
274+
'question_type',
275+
'_pending_handlers',
276+
'_service_state_changed',
277+
'query_scheduler',
278+
'done',
279+
'_first_request',
280+
'_next_send_timer',
281+
'_query_sender_task',
282+
)
283+
264284
def __init__(
265285
self,
266286
zc: 'Zeroconf',

src/zeroconf/_services/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ServiceRegistry:
3333
the event loop as it is not thread safe.
3434
"""
3535

36+
__slots__ = ("_services", "types", "servers")
37+
3638
def __init__(
3739
self,
3840
) -> None:

0 commit comments

Comments
 (0)