From ed1b8795766e71416d6955412f782f4960547ccc Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Oct 2023 16:16:17 -0400 Subject: Do not call getfullargspec on every call. (#16589) getfullargspec is relatively expensive and the results will not change between calls, so precalculate it outside the wrapper. --- changelog.d/16589.misc | 1 + synapse/logging/opentracing.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog.d/16589.misc diff --git a/changelog.d/16589.misc b/changelog.d/16589.misc new file mode 100644 index 0000000000..6e69368bbf --- /dev/null +++ b/changelog.d/16589.misc @@ -0,0 +1 @@ +Improve performance when using opentracing. diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 4454fe29a5..e297fa9c8b 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -1019,11 +1019,14 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]: if not opentracing: return func + # getfullargspec is somewhat expensive, so ensure it is only called a single + # time (the function signature shouldn't change anyway). + argspec = inspect.getfullargspec(func) + @contextlib.contextmanager def _wrapping_logic( - func: Callable[P, R], *args: P.args, **kwargs: P.kwargs + _func: Callable[P, R], *args: P.args, **kwargs: P.kwargs ) -> Generator[None, None, None]: - argspec = inspect.getfullargspec(func) # We use `[1:]` to skip the `self` object reference and `start=1` to # make the index line up with `argspec.args`. # -- cgit 1.4.1