[Python-3000] Adaptation vs. Generic Functions

Guido van Rossum guido at python.org
Fri Apr 7 21:19:17 CEST 2006


On 4/7/06, Guido van Rossum <guido at python.org> wrote:
> Even with the cache I put in? The hairy algorithm doesn't get invoked
> more than once per actual signature (type tuple).

OK, I timed this, and the @overloaded function (when it hits the
cache) is indeed 4-7 times slower than a handwritten decision tree
with about 5 cases (depending on which case gets hit).

But I can make the @overloaded function twice as fast by in-lining the
first few lines of find_func() and using a different expression for
calculating the types tuple:

    tuple(map(type, args))

(despite allocating a throw-away list first) is more than twice as fast as

    tuple(type(a) for a in args)

and that's where most of the time went. A bit of speedup also came
from avoiding to call find_func() if there's a cache hit. So I think
that with some additional effort and/or a tiny bit of C code, the
speed issue *when the cache works* can be solved.

Is the performance of the full-fledged algorithm really that much of an issue?

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list