feat: speed up ServiceInterface callbacks with cython methods (#274)
This commit is contained in:
@@ -933,7 +933,7 @@ class BaseMessageBus:
|
|||||||
if not interfaces:
|
if not interfaces:
|
||||||
return None
|
return None
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
methods = ServiceInterface._get_methods(interface)
|
methods = ServiceInterface._c_get_methods(interface)
|
||||||
for method in methods:
|
for method in methods:
|
||||||
if method.disabled:
|
if method.disabled:
|
||||||
continue
|
continue
|
||||||
@@ -943,7 +943,7 @@ class BaseMessageBus:
|
|||||||
and msg.member == method.name
|
and msg.member == method.name
|
||||||
and msg.signature == method.in_signature
|
and msg.signature == method.in_signature
|
||||||
):
|
):
|
||||||
return ServiceInterface._get_handler(interface, method, self)
|
return ServiceInterface._c_get_handler(interface, method, self)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -24,3 +24,9 @@ cdef class ServiceInterface:
|
|||||||
cdef list __signals
|
cdef list __signals
|
||||||
cdef set __buses
|
cdef set __buses
|
||||||
cdef dict __handlers
|
cdef dict __handlers
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
cdef list _c_get_methods(ServiceInterface interface)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
cdef object _c_get_handler(ServiceInterface interface, _Method method, object bus)
|
||||||
|
|||||||
@@ -455,6 +455,13 @@ class ServiceInterface:
|
|||||||
def _get_methods(interface: "ServiceInterface") -> List[_Method]:
|
def _get_methods(interface: "ServiceInterface") -> List[_Method]:
|
||||||
return interface.__methods
|
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
|
@staticmethod
|
||||||
def _get_signals(interface: "ServiceInterface") -> List[_Signal]:
|
def _get_signals(interface: "ServiceInterface") -> List[_Signal]:
|
||||||
return interface.__signals
|
return interface.__signals
|
||||||
@@ -469,6 +476,14 @@ class ServiceInterface:
|
|||||||
) -> Callable[[Message, Callable[[Message], None]], None]:
|
) -> Callable[[Message, Callable[[Message], None]], None]:
|
||||||
return interface.__handlers[bus][method]
|
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
|
@staticmethod
|
||||||
def _add_bus(
|
def _add_bus(
|
||||||
interface: "ServiceInterface",
|
interface: "ServiceInterface",
|
||||||
|
|||||||
Reference in New Issue
Block a user