Thanks for explaining the differences tho. I got confused between the decorator and the decorator factory, thinking the decorator had a function inside it. Sorry :)

On Sat, Jan 2, 2016 at 10:42 PM, Nick Coghlan <> wrote:
On 3 January 2016 at 13:48, Guido van Rossum <> wrote:
> Whoops, Nick already did the micro-benchmarks, and showed that creating a
> function object is faster than instantiating a class. He also measured the
> size, but I think he forgot that sys.getsizeof() doesn't report the size
> (recursively) of contained objects -- a class instance references a dict
> which is another 288 bytes (though if you care you can get rid of this by
> using __slots__).

You're right I forgot to account for that (54 bytes without __slots__
did seem surprisingly small!), but functions also always allocate
f.__annotations__ at the moment.

Always allocating f.__annotations__ actually puzzled me a bit - did we
do that for a specific reason, or did we just not think of setting it
to None when it's unused to save space the way we do for other
function attributes? (__closure__, __defaults__, etc)


Nick Coghlan   |   |   Brisbane, Australia

-Surya Subbarao