feat: speed up ServiceInterface callbacks with cython methods (#274)

This commit is contained in:
J. Nick Koston 2023-12-03 18:26:29 -10:00 committed by GitHub
parent d47622c490
commit 0e57d798a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -933,7 +933,7 @@ class BaseMessageBus:
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
@ -943,7 +943,7 @@ class BaseMessageBus:
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

View File

@ -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)

View File

@ -455,6 +455,13 @@ class ServiceInterface:
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
@ -469,6 +476,14 @@ class ServiceInterface:
) -> 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",