[Python-Dev] Replacing self.dict in init (original) (raw)
INADA Naoki songofacandy at gmail.com
Sun Mar 25 21:43:45 EDT 2018
- Previous message (by thread): [Python-Dev] Replacing self.__dict__ in __init__
- Next message (by thread): [Python-Dev] Replacing self.__dict__ in __init__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Previous message (by thread): [Python-Dev] Replacing self.__dict__ in __init__
- Next message (by thread): [Python-Dev] Replacing self.__dict__ in __init__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]