[Python-Dev] Replacing self.__dict__ in __init__

Serhiy Storchaka storchaka at gmail.com
Sun Mar 25 12:51:42 EDT 2018


25.03.18 18:38, Tin Tvrtković пише:
> For example, for a simple class with 9 attributes:

What are results for classes with 2 or 100 attributes? What are results 
in Python 3.5?

I think you are playing on thin ice. Your results depend on 
implementation details of the bytecode (in particularly on adding 
BUILD_CONST_KEY_MAP in 3.6). Other implementations use different 
bytecode or don't use bytecode at all. CPython can introduce new opcodes 
in future versions which will change your result drastically. And the 
straightforward way could become the most fast.

I suggest you to not worry and just wait for more general optimizations 
in CPython interpreter.



More information about the Python-Dev mailing list