Skip to content

Commit

Permalink
feat: improve ServiceBrowser performance by removing OrderedDict (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Apr 2, 2023
1 parent d3213d7 commit 9a16be5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/zeroconf/_services/browser.py
Expand Up @@ -26,7 +26,6 @@
import threading
import warnings
from abc import abstractmethod
from collections import OrderedDict
from typing import (
TYPE_CHECKING,
Callable,
Expand Down Expand Up @@ -302,7 +301,7 @@ def __init__(
self.port = port
self.multicast = self.addr in (None, _MDNS_ADDR, _MDNS_ADDR6)
self.question_type = question_type
self._pending_handlers: OrderedDict[Tuple[str, str], ServiceStateChange] = OrderedDict()
self._pending_handlers: Dict[Tuple[str, str], ServiceStateChange] = {}
self._service_state_changed = Signal()
self.query_scheduler = QueryScheduler(self.types, delay, _FIRST_QUERY_DELAY_RANDOM_INTERVAL)
self.done = False
Expand Down Expand Up @@ -551,5 +550,6 @@ def async_update_records_complete(self) -> None:
This method will be run in the event loop.
"""
while self._pending_handlers:
self.queue.put(self._pending_handlers.popitem(False))
for pending in self._pending_handlers.items():
self.queue.put(pending)
self._pending_handlers.clear()
5 changes: 3 additions & 2 deletions src/zeroconf/asyncio.py
Expand Up @@ -89,8 +89,9 @@ def async_update_records_complete(self) -> None:
This method will be run in the event loop.
"""
while self._pending_handlers:
self._fire_service_state_changed_event(self._pending_handlers.popitem(False))
for pending in self._pending_handlers.items():
self._fire_service_state_changed_event(pending)
self._pending_handlers.clear()


class AsyncZeroconfServiceTypes(ZeroconfServiceTypes):
Expand Down

0 comments on commit 9a16be5

Please sign in to comment.