4 ms·
I wish that you could use typed Python to speed up the execution of the program instead of them just being hints.
by ZephyrBlu 6y ago
I wish that you could use typed Python to speed up the execution of the program instead of them just being hints.
- m_mueller 6y agoafaik that was first planned for Python 4 and then dropped again :(
- ZephyrBlu 6y agoAny links on it being planned for Python 4? I didn't know they'd ever even considered it.
- m_mueller 6y agoI think that the mentions of that have been deleted from the relevant PEP since, but e.g. https://www.reddit.com/r/Python/comments/7zvyhx/pep_563_mentions_python_40_whats_going_on/ https://www.reddit.com/r/Python/comments/7zvyhx/pep_563_ment... is also asking about it.
- isoprophlex 6y agoNot exactly what you're talking about, but... For some types of functions, Numba's JIT offers some pretty nice speed ups. It can infer function types (or you supply them yourself) and compiles to optimized machine code
- chriswarbo 6y agoIt's tricky, since only the typed part can be sped up, and there will usually be lots of back-and-forth between typed and untyped code; which requires conversions and checks. For comparison, Racket has gradual typing which gives a speed boost when everything is typed, but can end up much slower if anything remains untyped, e.g. see figure 3 in http://www.ccis.northeastern.edu/home/types/publications/gradual-dead/pre-treatment.pdf http://www.ccis.northeastern.edu/home/types/publications/gra... Python would probably be even worse, since it's "more dynamic" than Racket; e.g. there are many hooks that can run arbitrary code (like dunder methods), and there's little encapsulation so values may get swapped out via monkey-patching at any time.
- Jiejeing 6y agoBut that is precisely what mypyc[0] is doing! It is part of mypy, and it compiles type-valid python files to cpython binary extensions, and takes advantage of a lot of shortcuts available to cut execution time. It is still a bit early to advocate for its use everywhere, and has it drawbacks (extensions compiled with mypyc will also typecheck the inputs and outputs of the module at runtime, which is great for improving code quality and validity of the annotations, but also means you may get TypeErrors in production if you hit a bad edge case). If there is no shortcut it will fallback to normal, slow, python performance, with some smallish benefits (e.g. vtables for attribute lookups, no parsing time, etc). [0] https://mypyc.readthedocs.io/ https://mypyc.readthedocs.io/
- goodpoint 6y agoNim feels very close to a typed Python.