Useful? __slots__ for functions

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue May 25 01:50:32 EDT 2004


Nick Jacobson wrote:

> The __slots__ attribute of new-style classes can reduce memory usage
> when there are millions of instantiations of a class.
> 
> So would a __slots__ attribute for functions/methods have a similar
> benefit?  i.e. could a function using __slots__ use significantly less
> memory, and therefore run faster, if called millions of times?

If you're talking about local names being in an indexed array (or
__slots__) then the time machine has got you.

Local names in functions (or rather, code objects) are resolved using a
simple index rather than a dictionary lookup.

Tim Delaney




More information about the Python-list mailing list