From b7a93ed4e0308bc58ed63c9410a4d770c44c66db Mon Sep 17 00:00:00 2001 From: Sergey Dobrov Date: Tue, 23 Apr 2024 14:32:08 +0200 Subject: [PATCH] make the export work much faster functions that are wrapped into `@unwrap` are used very intensively and are quite slow because they use introspection at each single call. this commit improves it by a lot by introspecting the function signature at the moment of wrapping and then reusing this information to avoid evaluating it over and over again improving the performance --- commcare_export/misc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/commcare_export/misc.py b/commcare_export/misc.py index f399e605..22dd1958 100644 --- a/commcare_export/misc.py +++ b/commcare_export/misc.py @@ -22,13 +22,15 @@ def digest_file(path): def unwrap(arg_name): def unwrapper(fn): + sig = inspect.signature(fn) + parameters = list(sig.parameters.keys()) + position = parameters.index(arg_name) @functools.wraps(fn) def _inner(*args): - callargs = inspect.getcallargs(fn, *args) - val = callargs[arg_name] - callargs[arg_name] = unwrap_val(val) - return fn(**callargs) + args = list(args) + args[position] = unwrap_val(args[position]) + return fn(*args) return _inner