New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jit and gil #362
Comments
|
Speaking about JIT, there is already the existing issue: #300. |
|
On the subject of the GIL, ideally it would be nice to build a GIL-less python, but it's not something we've done any work on yet. My expectation is that once we add the threading library Rust will start screaming that nothing is thread safe, and we'll have to add locks to make it run. I think we'll be aiming to add fine grained locks and see how it goes. The experience of CPython is that it's difficult to add more fine grained locking without breaking single core performance. Rust's safety checks might make this an easier task than in C, but that's just speculation at this stage. And then there's the question of C extensions that expect to be able to acquire the GIL, so we may need an optional GIL for compatibility anyway. In short, it's a very interesting can of worms without an easy answer. |
|
As any regular user I'm not that interested what language an interpreter is written in. The whole point of switching to another interpreter (like pypy) is it's speed and/or concurrency (jython). So for the project to be successful I think it should have great compatibility with cpython and offer other benefits, even if it means that more code will be placed to unsafe blocks. |
|
@Yanpas In Python there's thread-level concurrency and there's process-level parallelism. It sounds like what you want is thread-level parallelism. The GIL is what prevents thread-level parallelism. As far as I know there are three strategies for thread-level parallelism in Python: 'Software Transactional Memory', subinterpreters, and OS thread backed Python threads. Transactional Memory treats thread operations as atomic. Either a thread can successfully execute, or it is reset and tries again. In the case of memory access, each thread tries to perform a memory access. The first thread to complete the access moves on to the next stage in it's execution. The threads that cannot complete it reset to the beginning of the access attempt and try again. PyPy has experimented with Transactional Memory. Given the young nature of RustPython, I think some of the challenges PyPy has run into could be avoided. It is a promising avenue for retro-fitting thread-level parallelism into Python. Wikipedia on 'Software Transactional Memory' There is also the subinterpreter PEP. This proposal exposes CPython's ability to spawn isolated interpreters in their own OS thread to the user through a module. Subinterpreters can be coupled with channels to implement 'goroutine' like structures (which are lock-free). Finally OS thread back Python threads would require the interpreter to execute threads without the GIL. Regardless of which approach is taken (if any), I think it would be beneficial to make the VM multi-threaded. A multi-threaded VM allows for things like multi-threaded GC. It also allows for runtime optimizations such as automatic parallel execution of loops. And the simple fact is multi-threaded processors are the norm, and to stay single-threaded is to let the bulk of the processor sit idle. A first step might be replacing Rc with Arc |
|
I suppose the major possible improvement that Rust can produce will be based on its built-in concurrency. As far as I can understand, this project is in the early phase in which the first step to a better Python interpreter is to clone CPython standard library in Rust and keep them in sync as much as possible. After that it will be possible to unleash all the advantages that Rust can bring in terms of concurrency, safety and savings in maintenance time. |
|
I am rather new to the subject, but of course a GIL less python that is capable of multi threading would be of a great advantage. The way CPython is implemented makes it almost impossible to remove the GIL any attempt let to a huge amount of extra logs distributed all over different parts of the implementation slowing everything massively down. |
|
basic jit with cranelift is recently added |
Also, Cython is solidly mature at this point and creating functions that are C/Cython-only (any code that does not use the Python C API) can have the |
|
It seems that the current implementation uses OS thread for threading, but uses a lot of atomics for synchronization. I wonder if it is possible to have some kind of memory model that requires the user to explicitly synchronize the data, similar to using synchronize and volatile in Java. AFAIK, this is not defined for Python. As mentioned in #2445 and #2474, atomic is causing serious performance issues, and the running time of simple programs increase linearly as the number of threads. We should try to minimize the synchronization needed for executing the code. |


Yanpas commentedFeb 6, 2019
•
edited
One of the reasons why cpython is the slowest one is that it is interpreted. Do you have plans to support jit? And will you keep gil?
UPD:
As any regular user I'm not that interested what language an interpreter is written in. The whole point of switching to another interpreter (like pypy) is it's speed and/or concurrency (jython). So for the project to be successful I think it should have great compatibility with cpython and offer other benefits, even if it means that more code will be placed to unsafe blocks.
The text was updated successfully, but these errors were encountered: