Speed: bytecode vz C API calls

Terry Reedy tjreedy at udel.edu
Mon Dec 8 12:47:29 EST 2003


"Jacek Generowicz" <jacek.generowicz at cern.ch> wrote in message
news:tyf7k171jbq.fsf at pcepsft001.cern.ch...
> I have a program in which I make very good use of a memoizer:
>
>   def memoize(callable):
>       cache = {}
>       def proxy(*args):
>           try: return cache[args]
>           except KeyError: return cache.setdefault(args, callable(*args))
>       return proxy
...
> I've got to the stage where my program is still not fast enough, and
> calls to the memoizer proxy are topping profiler output table. So I
> thought I'd try to see whether I can speed it up by recoding it in C.

Have you tried psyco on above?  Or rather, on the proxies?
Can any of your callables be memoized by list rather than dict?
(ie, any count or restricted int args?)

If you have just a few wrapped functions, faster, special-cased proxies
(with exact arg lists) would be feasible and possibly easier for psyco.
Special-casing would include inlining the callable when possible
-- or rather, inlining the memoization within the function.

TJR






More information about the Python-list mailing list