[Python-ideas] Bad programming style in decorators?

Nick Coghlan ncoghlan at gmail.com
Sun Jan 3 01:42:13 EST 2016


On 3 January 2016 at 13:48, Guido van Rossum <guido at python.org> 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)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list