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.pull/16587/merge
parent
cfb6d38c47
commit
ed1b879576
|
@ -0,0 +1 @@
|
||||||
|
Improve performance when using opentracing.
|
|
@ -1019,11 +1019,14 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]:
|
||||||
if not opentracing:
|
if not opentracing:
|
||||||
return func
|
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
|
@contextlib.contextmanager
|
||||||
def _wrapping_logic(
|
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]:
|
) -> Generator[None, None, None]:
|
||||||
argspec = inspect.getfullargspec(func)
|
|
||||||
# We use `[1:]` to skip the `self` object reference and `start=1` to
|
# We use `[1:]` to skip the `self` object reference and `start=1` to
|
||||||
# make the index line up with `argspec.args`.
|
# make the index line up with `argspec.args`.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue