Skip to content

Commit

Permalink
feat: speed up ServiceInterface callbacks with cython methods (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 4, 2023
1 parent d47622c commit 0e57d79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def _find_message_handler(
if not interfaces:
return None
for interface in interfaces:
methods = ServiceInterface._get_methods(interface)
methods = ServiceInterface._c_get_methods(interface)
for method in methods:
if method.disabled:
continue
Expand All @@ -943,7 +943,7 @@ def _find_message_handler(
and msg.member == method.name
and msg.signature == method.in_signature
):
return ServiceInterface._get_handler(interface, method, self)
return ServiceInterface._c_get_handler(interface, method, self)

return None

Expand Down
6 changes: 6 additions & 0 deletions src/dbus_fast/service.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ cdef class ServiceInterface:
cdef list __signals
cdef set __buses
cdef dict __handlers

@staticmethod
cdef list _c_get_methods(ServiceInterface interface)

@staticmethod
cdef object _c_get_handler(ServiceInterface interface, _Method method, object bus)
15 changes: 15 additions & 0 deletions src/dbus_fast/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ def _get_properties(interface: "ServiceInterface") -> List[_Property]:
def _get_methods(interface: "ServiceInterface") -> List[_Method]:
return interface.__methods

@staticmethod
def _c_get_methods(interface: "ServiceInterface") -> List[_Method]:
# _c_get_methods is used by the C code to get the methods for an
# interface
# https://github.com/cython/cython/issues/3327
return interface.__methods

@staticmethod
def _get_signals(interface: "ServiceInterface") -> List[_Signal]:
return interface.__signals
Expand All @@ -469,6 +476,14 @@ def _get_handler(
) -> Callable[[Message, Callable[[Message], None]], None]:
return interface.__handlers[bus][method]

@staticmethod
def _c_get_handler(
interface: "ServiceInterface", method: _Method, bus: "BaseMessageBus"
) -> Callable[[Message, Callable[[Message], None]], None]:
# _c_get_handler is used by the C code to get the handler for a method
# https://github.com/cython/cython/issues/3327
return interface.__handlers[bus][method]

@staticmethod
def _add_bus(
interface: "ServiceInterface",
Expand Down

0 comments on commit 0e57d79

Please sign in to comment.