[Python-ideas] PEP 3155 - Qualified name for classes and functions
Nick Coghlan
ncoghlan at gmail.com
Mon Oct 31 22:52:18 CET 2011
On Tue, Nov 1, 2011 at 5:37 AM, Jim Jewett <jimjjewett at gmail.com> wrote:
> On Mon, Oct 31, 2011 at 10:33 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> On Mon, 31 Oct 2011 10:17:14 -0400
>> Jim Jewett <jimjjewett at gmail.com> wrote:
>>> How meaningful are the extra two slots for every function or class object?
>>
>> It's only one extra slot per function or class.
>
> OK; I was thinking of both the object qname and its module's qname,
> but I agree that they are separable.
Yeah, adding __qmodule__ is part of the module aliasing PEP (395)
rather than this one.
It's technically not needed for functions (you could do
f.func_globals["__qname__"] instead), but classes definitely need it
in order to kill off the corner cases that currently force developers
to choose between breaking serialisation and breaking pickling.
The main differences between __qname__ and __qmodule__ and the Unicode
changes are that there are a *lot* of small strings in any Python
application, and an additional pointer or two can make a reasonably
significant difference to their size, but classes and functions are
already relatively complex objects.
On trunk:
>>> def f(): pass
...
>>> class C(): pass
...
>>> import sys
>>> sys.getsizeof("")
60
>>> sys.getsizeof(f)
136
>>> sys.getsizeof(C)
832
(And those numbers don't even take into account the size of
automatically created subobjects like C.__dict__, f.__dict__,
f.__code__, etc)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list