This PR aims to improve the performances of memoize_by_id decorator while preserving the external signature.
By profiling the code I've noticed that a lot of time is spent into the generation of the cache key of @memoize_by_id decorator (specifically on the execution ofinspect.getcallargs(func, *args, **kwargs).
This PR adds a small optimisation on the make_key functionality if the function is invoked with kwargs only parameters.
In such condition we don't need to use getcallargs to determine the mappings between parameter names and associated values.
In order to preserve the fact that getcallargs resolves default attributes as well the added code does manually deal with them (it's a bit ugly but by doing so we can get additional performance improvements).
Coverage decreased (-0.1%) to 97.78% when pulling ef76678cb73e1da7d9be6016706bec48e73fade8 on macisamuele:maci-improve-memoize-by-id-if-used-with-kwargs-only into 815f95e89bac42c6efd2d28a54b955017a5b4428 on Yelp:master.
This PR aims to improve the performances of
memoize_by_id
decorator while preserving the external signature.By profiling the code I've noticed that a lot of time is spent into the generation of the cache key of
@memoize_by_id
decorator (specifically on the execution ofinspect.getcallargs(func, *args, **kwargs)
.This PR adds a small optimisation on the
make_key
functionality if the function is invoked with kwargs only parameters. In such condition we don't need to usegetcallargs
to determine the mappings between parameter names and associated values.In order to preserve the fact that
getcallargs
resolves default attributes as well the added code does manually deal with them (it's a bit ugly but by doing so we can get additional performance improvements).Data
Raw data on: https://gist.github.com/macisamuele/89fa006dbaf5c27a85200c96deb2a459
Unmarshaling performance improvement: