5 ms·
Python’s type hints have nothing to do with speed.
by yzmtf2008 8y ago
Python’s type hints have nothing to do with speed.
- scardine 8y agoSince the typing module used to be one of the slowest modules in core you paid a performance penalty even if cpython does no care about type annotations (improved in 3.7). So it does have something to do with performance... There are other implementations and Python supersets that do use type annotations for optimization and I don't see this trend slowing.
- xapata 8y agoCython, you mean? There's not really a need for type hints to create speed. A tracing JIT can infer type pretty well.
- icegreentea2 8y agoNo he means CPython. While the meaning of the annotations are ignored at runtime, the typing library still has to be imported and typing annotations evaluated (as it evaluate that the type annotation has a value of List[int], not to check that the value tagged with the type annotation actually has that value). As a result, in CPython 3.6 a module that has been type hinted will import slower than one that doesn't.
- xapata 8y ago> Python supersets that do use type annotations for optimization Such as Cython.