3 ms·
I wonder why much speedup could be gained by having a control over Python’s dynamism. Dynamic attributes, etc. are not needed in most of normal application code
by miohtama 3y ago
I wonder why much speedup could be gained by having a control over Python’s dynamism. Dynamic attributes, etc. are not needed in most of normal application code that is not meta heavy. Could there be any gains via making backwards incompatible changes e.g. by sealing some modules or functions to be “static” only?
It would not matter if a subset of an application is partially incompatible, as often one wants to optimise smaller hot code paths only.
- karamanolev 3y agoIsn't that the whole idea behind mypyc? I don't know what performance gains are realized though, as I haven't tested it. We're in the process of typing a 300 KLOC codebase mostly for the correctness benefits, not so much performance.
- jjnoakes 3y agoMojo is taking this approach. I think it's a good idea.
- ux 3y agoOne thing you can do as a user already today to reduce Python dynamism of classes is using __slots__: https://wiki.python.org/moin/UsingSlots https://wiki.python.org/moin/UsingSlots. I enjoy this a lot, not only for the memory and access performance boost, but because it also makes the code more rigid (and thus more resilient to monkey code attacks).
- miohtama 3y agoYes, already using __slots__ heavily. Since Python 3.10 you can also do @dataclass(slots=True) Class MyClass: pass