Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python’s type hints have nothing to do with speed.


Since 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.


Cython, you mean? There's not really a need for type hints to create speed. A tracing JIT can infer type pretty well.


No 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.


> Python supersets that do use type annotations for optimization

Such as Cython.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: