Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: speed up the service registry with a cython pxd #1226

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

Merged
merged 1 commit into from
Aug 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def build(setup_kwargs: Any) -> None:
"src/zeroconf/_listener.py",
"src/zeroconf/_protocol/incoming.py",
"src/zeroconf/_protocol/outgoing.py",
"src/zeroconf/_services/registry.py",
],
compiler_directives={"language_level": "3"}, # Python 3
),
Expand Down
18 changes: 18 additions & 0 deletions 18 src/zeroconf/_services/registry.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import cython


cdef class ServiceRegistry:

cdef cython.dict _services
cdef public cython.dict types
cdef public cython.dict servers

@cython.locals(
record_list=cython.list,
)
cdef _async_get_by_index(self, cython.dict records, str key)

cdef _add(self, object info)

cdef _remove(self, cython.list infos)
5 changes: 4 additions & 1 deletion 5 src/zeroconf/_services/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def async_get_infos_server(self, server: str) -> List[ServiceInfo]:

def _async_get_by_index(self, records: Dict[str, List], key: str) -> List[ServiceInfo]:
"""Return all ServiceInfo matching the index."""
return [self._services[name] for name in records.get(key, [])]
record_list = records.get(key)
if record_list is None:
return []
return [self._services[name] for name in record_list]

def _add(self, info: ServiceInfo) -> None:
"""Add a new service under the lock."""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.