mirror of
https://github.com/element-hq/synapse.git
synced 2026-05-18 11:55:25 +00:00
Do not do opentracing wrapping if tracing is disabled
This shows up in profiles as wasted CPU time.
This commit is contained in:
@@ -943,6 +943,10 @@ def _custom_sync_async_decorator(
|
||||
async def _wrapper(
|
||||
*args: P.args, **kwargs: P.kwargs
|
||||
) -> Any: # Return type is RInner
|
||||
# Short-circuit: if opentracing was disabled after decoration time
|
||||
# (init_tracer sets opentracing=None), skip all wrapping overhead.
|
||||
if opentracing is None:
|
||||
return await func(*args, **kwargs) # type: ignore[unreachable]
|
||||
# type-ignore: func() returns R, but mypy doesn't know that R is
|
||||
# Awaitable here.
|
||||
with wrapping_logic(func, *args, **kwargs): # type: ignore[arg-type]
|
||||
@@ -953,6 +957,11 @@ def _custom_sync_async_decorator(
|
||||
# `@defer.inlineCallbacks` or that return a `Deferred` or other `Awaitable`.
|
||||
@wraps(func)
|
||||
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
|
||||
# Short-circuit: if opentracing was disabled after decoration time
|
||||
# (init_tracer sets opentracing=None), skip all wrapping overhead.
|
||||
if opentracing is None:
|
||||
return func(*args, **kwargs) # type: ignore[unreachable]
|
||||
|
||||
scope = wrapping_logic(func, *args, **kwargs)
|
||||
scope.__enter__()
|
||||
|
||||
|
||||
@@ -455,9 +455,7 @@ class DeferredCacheListDescriptor(_CacheDescriptorBase):
|
||||
cache_entry.error_bulk(cache, missing, f)
|
||||
|
||||
args_to_call = dict(arg_dict)
|
||||
args_to_call[list_name] = {
|
||||
cache_key_to_arg(key) for key in missing
|
||||
}
|
||||
args_to_call[list_name] = {cache_key_to_arg(key) for key in missing}
|
||||
|
||||
# dispatch the call, and attach the two handlers
|
||||
missing_d = defer.maybeDeferred(
|
||||
@@ -710,4 +708,4 @@ def _get_cache_key_gen(
|
||||
pos += 1
|
||||
else:
|
||||
if inc:
|
||||
yield param_defaults[nm]
|
||||
yield param_defaults[nm]
|
||||
|
||||
Reference in New Issue
Block a user