A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-March/152485.html below:

[Python-Dev] Replacing self.__dict__ in __init__

[Python-Dev] Replacing self.__dict__ in __init__INADA Naoki songofacandy at gmail.com
Sun Mar 25 21:43:45 EDT 2018
>
> The dict can be replaced during __init__() and still get benefits of key-sharing.  That benefit is lost only when the instance dict keys are modified downstream from __init__().  So, from a dict size point of view, your optimization is fine.
>

I think replacing __dict__ lose key-sharing.


Python 3.6.4 (default, Mar  9 2018, 23:15:03)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class C:
...   def __init__(self, a, b, c):
...     self.a, self.b, self.c = a, b, c
...
>>> class D:
...   def __init__(self, a, b, c):
...     self.__dict__ = {'a':a, 'b':b, 'c':c}
...
>>> import sys
>>> sys.getsizeof(C(1,2,3).__dict__)
112
>>> sys.getsizeof(D(1,2,3).__dict__)
240


-- 
INADA Naoki  <songofacandy at gmail.com>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4