Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Do not call getfullargspec on every call. (#16589)
Browse files Browse the repository at this point in the history
getfullargspec is relatively expensive and the results will
not change between calls, so precalculate it outside the
wrapper.
  • Loading branch information
clokep authored Oct 31, 2023
1 parent cfb6d38 commit ed1b879
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/16589.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance when using opentracing.
7 changes: 5 additions & 2 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
#
Expand Down

0 comments on commit ed1b879

Please sign in to comment.