From eddd5dcc808fdc2a61954425fbf2fe4c0e7567b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 4 Nov 2023 16:06:33 -0500 Subject: [PATCH] feat: speed up ServiceBrowsers with a pxd for the signal interface --- build_ext.py | 1 + src/zeroconf/_services/__init__.pxd | 11 +++++++++++ src/zeroconf/_services/browser.pxd | 1 + src/zeroconf/_services/browser.py | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/zeroconf/_services/__init__.pxd diff --git a/build_ext.py b/build_ext.py index 2134f61d4..ba80e52c3 100644 --- a/build_ext.py +++ b/build_ext.py @@ -33,6 +33,7 @@ def build(setup_kwargs: Any) -> None: "src/zeroconf/_handlers/record_manager.py", "src/zeroconf/_handlers/multicast_outgoing_queue.py", "src/zeroconf/_handlers/query_handler.py", + "src/zeroconf/_services/__init__.py", "src/zeroconf/_services/browser.py", "src/zeroconf/_services/info.py", "src/zeroconf/_services/registry.py", diff --git a/src/zeroconf/_services/__init__.pxd b/src/zeroconf/_services/__init__.pxd new file mode 100644 index 000000000..46a75f3c5 --- /dev/null +++ b/src/zeroconf/_services/__init__.pxd @@ -0,0 +1,11 @@ + +import cython + + +cdef class Signal: + + cdef list _handlers + +cdef class SignalRegistrationInterface: + + cdef list _handlers diff --git a/src/zeroconf/_services/browser.pxd b/src/zeroconf/_services/browser.pxd index 8b77c80e3..a844d3330 100644 --- a/src/zeroconf/_services/browser.pxd +++ b/src/zeroconf/_services/browser.pxd @@ -5,6 +5,7 @@ from .._cache cimport DNSCache from .._protocol.outgoing cimport DNSOutgoing, DNSPointer, DNSQuestion, DNSRecord from .._updates cimport RecordUpdateListener from .._utils.time cimport current_time_millis, millis_to_seconds +from . cimport Signal, SignalRegistrationInterface cdef bint TYPE_CHECKING diff --git a/src/zeroconf/_services/browser.py b/src/zeroconf/_services/browser.py index c302de546..89b24e48b 100644 --- a/src/zeroconf/_services/browser.py +++ b/src/zeroconf/_services/browser.py @@ -388,7 +388,7 @@ def _enqueue_callback( state_change is SERVICE_STATE_CHANGE_ADDED or ( state_change is SERVICE_STATE_CHANGE_REMOVED - and self._pending_handlers.get(key) != SERVICE_STATE_CHANGE_ADDED + and self._pending_handlers.get(key) is not SERVICE_STATE_CHANGE_ADDED ) or (state_change is SERVICE_STATE_CHANGE_UPDATED and key not in self._pending_handlers) ):