pytoolz/toolz — pull request #57 by mrocklin (2013-10-31 21:16:06+00:00)
Title: memoize _num_required_args

In https://github.com/pytoolz/toolz/pull/52 I leveraged the `inspect` module to catch more errors in curried functions before execution. Unfortunately when the same curried function is called many times (for example if it is mapped onto a list) then this results in very many inspect calls. These are both expensive and needless.

A simple fix is to memoize the function that calls `inspect`. This performs well in practice but introduces a potential memory leak. Alternatives might include introducing some additional state into `curry` or implementing a fixed-sized dictionary for use as an LRU cache in memoize.

I'm inclined to stay with this for the moment because the leak is not very bad, the stored key/value pairs are of type `(function, int)`