eprbell / dali-rp2

DaLI (Data Loader Interface) is a data loader and input generator for RP2 (https://pypi.org/project/rp2), the privacy-focused, free, open-source cryptocurrency tax calculator: DaLI removes the need to manually prepare RP2 input files. Just like RP2, DaLI is also free, open-source and it prioritizes user privacy.
https://pypi.org/project/dali-rp2/
Apache License 2.0
63 stars 42 forks source link

Cache signature parameters during transaction initialization #152

Closed qwhelan closed 1 year ago

qwhelan commented 1 year ago

dali currently invokes inspect.signature() on every transaction initialization, which is the majority of the runtime after including https://github.com/eprbell/dali-rp2/pull/151. We start with a runtime of:

%timeit InTransaction('test', 'a', 'b', '2023-03-30 00:00:00Z', 'c', 'd', 'e', 'BUY', '1', '1')
97.2 µs ± 4.3 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

And by adding a class-level cache, we cut the runtime by ~2/3:

%timeit InTransaction('test', 'a', 'b', '2023-03-30 00:00:00Z', 'c', 'd', 'e', 'BUY', '1', '1')
35.1 µs ± 465 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)