RustPython – A Python-3 (CPython >= 3.11.0) Interpreter written in Rust
github.com
github.com
But if they interface with external libraries then some extra steps may be needed.
Not to take away from the excitement. I love Rust and cargo is great.
It can be more involved, it can be less involved.
For example https://github.com/servo/servo seems a bit involved to set up for development but at the same time not too bad either.
Since rust Python can theoretically access Tokio does it make it avoid the cpython gil issues
Is it an artificial artifact or is it necessary to make rust python work?
I looked at Nix to help with multi-language builds (and cross compiling), but only had limited success.
In practice, I'd expect libraries to just call make/cmake/ninja for you, or (like openssl-sys) ask you to install the necessary libraries using your favourite package manager.
Their github.io page mentions interesting use cases though:
> RustPython can be embedded into Rust programs to use Python as a scripting language for your application, or it can be compiled to WebAssembly in order to run Python in the browser
Some sort of sensible scripting language to do the game logic in.
It's also a tiny codebase which is easy to vendor and ship.
Python is also a decent glue language but creating a Python interpreter is a bunch more work and the API is a bit harder to work with.
The language is _tiny_ (and kept that way on purpose)
Aside from stuff like metatables(which may require you to play around for a bit to understand their value), you can pick it up in a couple of hours. I'm not even kidding. So much so that you see people modifying code without even looking at documentation.
and yes; i know that's a ridiculous example that's not really comparable for anything significant.
Impossible. Most developers outside the games industry don't even know it exists.
... and if they knew about it, they would use it much more.
The first problem is "Which Lua?" Lua, by itself, is almost completely useless. You first need to compile/install a bunch of things in order to make Lua useful. This has the Perl problem that everybody uses a different dialect of Lua.
The second part is that the Lua constructs for programming in the large are very weak. I believe that Adobe had a postmortem about this (Lightroom, I think?)
And then there is the language, itself. For me, the 1-based indexing is death in this day and age. Sorry. Zero-based is the dominant ecosystem and not fitting into that is simply not acceptable.
How is this any different from pretty much any language out there? From a quick eyeball of RustPython's Cargo.toml[1], there are about 70 different dependencies which all need to be compiled. I haven't worked too much with Autoconf, but I am pretty sure CPython has quite a few dependencies.
[1]: https://github.com/RustPython/RustPython/blob/main/Cargo.tom...
> The second part is that the Lua constructs for programming in the large are very weak.
This is deliberate because it forces you to use the tools you are given instead of reimplementing features that can already be implemented by using other primitives in Lua.
> I believe that Adobe had a postmortem about this (Lightroom, I think?)
I can't find this article. Has anyone else had any luck?
(1): e.g. awesome, blender
Furthermore tooling to work in such contexts (as a API consumer) often is very limited or does not exists, but the API producer seldomly has the time/money to produce such tooling either.
Lastly there is the remaining problem of Python by itself being really slow, for it's main use-cases this often doesn't matter as e.g. the scientific computations are run by native extensions python delegates the work, too. But this would mean that you have to also support native extensions support or hope that no extension needs to be really fast (not needing to be really fast is surprisingly often the case) or similar solutions. In turn choosing something which has a good JIT, AOT or similar compilation has benefits.
Not only did old examples often just not work, there was no serious code completion to facilitate creating anything from scratch.
Yeah we have mypy, but its not official and not integrated. And subsets that do have a performance benefit (like TorchScript) are niche and/or not sustainably supported.
Now all your imports, on the other hand...
Python was not the bottleneck, just the scapegoat for badly written code.
Currently it's more about clarity and a nice clean code base, but it can only get faster from here
http://www.dannyvankooten.com/blog/2022/rewriting-interprete...
Thanks!
RustPython even cannot run `1+1` without calling `int.__add__` yet. And it is working on https://github.com/RustPython/RustPython/pull/4615
So it still has long way to go not C vs Rust but from the design level.
Which is great for embedding or customizing your scripting language needs.
That being said, I've seen much worse languages being used to write compilers, so... who knows?
I'm much more nervous about maintaining invariants as you implement compilation passes, especially in the absence of powerful pattern-matching.
https://github.com/RustPython/RustPython/issues/1940#issueco...
CPython is also building a -no-gil compile-time option. If that gets traction, some of the big performance-oriented C extensions like Numpy etc would likely build a non-GIL extension version too.
Then, if RustPython's non-GIL implementation is compatible with CPython's, and their C ABI is compatible, those C extensions might work.
1. releasing the gil means multithreading is opt-in for a given code section in NumPy. Only very specific parts of the code need to be threadsafe.
2. not relying on a gil in cpython runtime means multithreading becomes opt out. Now all the code by default needs to be threadsafe, including the libs you depend on.
A lot of C/C++/Fortran scientific code is not thread safe, and the whole scientific python ecosystem depends heavily on those codebases.A quick check on master shows only 10-20 calls using NPY_BEGIN_ALLOW_THREADS (which is an alias to Py_BEGIN_ALLOW_THREADS).
A lot of the NumPy code manipulates python runtime objects, and doing so without thread safety would likely break everywhere. A lot of efforts would be needed to gradually make large C extension thread safe.
There are already other implementations. But CPython is the reference implementation. That's part of why we're only now seeing optimizations that reduce code clarity for reading. (i think, dont quote me on this)
[0] https://github.com/faster-cpython/ideas/blob/main/FasterCPyt...
I agree that it would be better, all else being equal, if CPython were implemented in a memory-safe language (though it would almost certainly need to use unsafe escape hatches in some places), but I think this'd be more viable if it were done by incrementally migrating the existing codebase with the involvement of the current maintainers, rather than as a third-party rewrite from scratch.
The hardest part of supplanting CPython is the fact that the FFI is already validated on a huge amount of implementations. I believe Cinder and Pyston work out of the box but they are on older versions of python but Pyston wants to be merged back into CPython and so does Cinder (or at least what is relevant). On the other hand JIT in CPython can be achieved by other python packages. Pyston has also extracted the JIT and can be added to 3.7 - 3.10 by installing it. See https://pypi.org/project/pyston/
Pypy is a separate reference implementations that has tried to achieve something different but hasn't supplanted python for years. It has had a JIT and the ability to change garbage collectors but the system stuffers when interacting with C FFIs
Pyodide is inthe browser so its something completely different but has no support for CFFIs.
IronPython (.net), Jython are inactive. Also GIL removal from CPython has been attempted multiple times but now that CPython is being funded by Microsoft to become faster makes it more unlikely that CPython will be supplanted.
But I think OS devs dont really want to put optimization work into GraalVM, as their hard worked could get sucked up and locked behind the Enterprise Edition.
But its Java support is most prominant, and the its runtime is significantly faster than OpenJDK.
Which is why its so promising for Python. I'd argue that OpenJDK is way ahead of the Pyton runtime, and GraalVM is way ahead of OpenJDK.
But its also kinda iffy because:
- Python support isn't very good now
- Oracle is Oracle. Hence they have the better optimizations walled off behind a "Enteprise Edition" registration and license.
The absolute number (or fraction) implemented in C is less important than the high profile ones. numpy/scipy alone are used in a huge number of projects so if you can't support those two libraries alone it's pretty much a non starter.
NumPy
pandas
Matplotlib
TensorFlow
PyTorch
These modules are critical to many of the workloads using Python (ML / AI / Data Science)There are a lot that use the C API, even if some of those aren't implemented in C (some are actually implemented in Rust.)