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

I am always keeping and eye on mypyc, typed_python (llvm Python compiler)[0] and nuitka[1]

I guess that because Python is extremely dynamic, we may never have a full everything-works compiler, but I’m excited about the possibility of this becoming some kind of intermediate step where different parts of the program get compiled when possible.

[0] https://github.com/APrioriInvestments/typed_python [1] https://github.com/Nuitka/Nuitka



We can have a compiler that does everything. It's just a matter of whether you have to stick the python interpreter in the compiled binary or not, or how much of it you have to use and whether you can only use the parts required. This is how a lot of Scheme compilers work, even though you still have `eval` and similar things.


Nuitka only removes interpreter overhead. (just 30%) It's still quite slow. To get real performance improvements, we'd need memory optimizations such as a modern JIT's hidden classes and shapes, which store data directly on the object, instead of inside a dictionary. https://mathiasbynens.be/notes/shapes-ics


Cython is also mentioned downthread.

typed_python is new to me. I'll check it out. I'm too am keeping an eye on this space. I think that compiling or transpiling python may be the solution to both the major problems I have with python: performance and distribution. Exciting times.


Have you considered Kotlin and Graal? It's obviously not Python, but Kotlin feels syntactically like Python meets Java, and since it compiles to byte code, you can do AoT compilation in Graal.

Edit: apparently GraalPython is a thing.


Syntactically, sure. But D is semantically a better combination of Python and Java. With `mixin`, you can `eval` arbitrary strings at compile time. You can call methods and use variables that are dynamically generated, like Python's `__getitem__` with D's `opDispatch`. You can generate code based on names and member variables using D's traits. You can use Python-like refcounting with `RefCounted!`. You can use Python's generators/iterators using D's lazy ranges, which are just as fast as manual for loops.[0] You can bind to Python with little effort using PyD. Just like Python, D has great C interop.

D compiles quickly and has much nicer syntax than C or C++.

[0]: https://forum.dlang.org/post/xbejngbluilrulstmmhu@forum.dlan...


There a new book about D for Python programmers.

"D, the Best Programming Language, for Former Python Developers: (Learn D Programming for Python Developers)"

https://www.amazon.com/Programming-Language-Former-Python-De...


Nim seems like a much more compelling alternative.

It generally feels pretty pythonic (At least as much as anything typed can), and it certainly scratches the "compiles to efficient machine code with no dependencies" itch.


The main benefit of Python is the ecosystem.


For ML and scientific work, yes. Aside from that, Java has a very good ecosystem. I personally think it's better than Python's, but they're both good.


In what concerns bindings to C, C++ and Fortran libraries, almost every language has them.


Kotlin Native also compiles to platform binaries.


Kotlin Native is going through a reboot after they realised making a memory model incompatible with JVM semantics wasn't that great idea after all.

Who would have guessed....


Have any links so that I can read up on this? I found this from last July[1].

[1] https://blog.jetbrains.com/kotlin/2020/07/kotlin-native-memo...


"Why the Kotlin/Native memory model cannot hold."

https://itnext.io/why-the-kotlin-native-memory-model-cannot-...


Thanks


I feel like it should be the agenda of the typed python syntax to allow writing annotated python code that can be compiled into a form that is as fast as equivalent c code.


I'd add Pythran to that list. It's a python to cpp compiler for numerical python. It achieves impressive speed ups often with very little adjustment of the numerical code. It's highly undervalued IMO, you get speed similar or better than highly optimized cython or c code with very little or no adjustments.

I compared it to cython, numba and Julia for DSO, which I wrote about here: https://jochenschroeder.com/blog/articles/DSP_with_Python2/


If you have a Python2 codebase, Shedskin also gives excellent speedups for numerical codes, the only thing that didn't see as good of a speed boost was string operations. Although that might be fixed.

https://shedskin.github.io/


If Tcl can be compiled (to a large degree, and without type annotations) to machine code (AOT) using TclQuadCode there's every hope for Python !


SELF, Lisp and Smalltalk are just as dynamic.

There isn't any Python dynamic feature that those languages lack, yet they solved out the problem a couple of decades ago, and SELF JIT is the genesis of HotSpot.

What Python lacks is JIT love and being too much attached to CPython.




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

Search: