Everything you need to know about Python 3.13 – JIT and GIL went up the hill
Python 3.13, releasing on October 2, 2024, introduces a free-threaded version allowing GIL disabling, enhancing multi-threading performance while potentially reducing single-threaded task performance by 20%.
Read original articleOn October 2, 2024, Python 3.13 will be released, introducing significant changes to its core functionality. The most notable updates include a "free-threaded" version of CPython that allows for the disabling of the Global Interpreter Lock (GIL) and the introduction of experimental Just-in-Time (JIT) compilation. The GIL has historically limited Python's ability to utilize multiple threads effectively, as it allows only one thread to execute bytecode at a time. This limitation was originally implemented to simplify memory management and garbage collection. However, as multi-core processors have become more common, the need for a more efficient threading model has increased. The transition to a free-threading mode will occur in phases, with the ultimate goal of removing the GIL entirely. Benchmarks indicate that while free-threading may lead to a performance degradation of around 20% for single-threaded tasks, it significantly enhances multi-threading performance. Users can experiment with these new features in the release candidate version of Python 3.13. The ongoing "Faster CPython" project, supported by Microsoft, aims to improve Python's performance further, making this release particularly significant for developers.
- Python 3.13 introduces a free-threaded version that can disable the GIL.
- The GIL has limited Python's multi-threading capabilities, which is being addressed due to the rise of multi-core processors.
- The transition to free-threading will occur in phases, with the goal of eventually removing the GIL.
- Benchmarks show a 20% performance drop for single-threaded tasks with free-threading but improved multi-threading performance.
- Users can try out the new features in the release candidate version of Python 3.13.
Related
Free-threaded CPython is ready to experiment with
CPython 3.13 introduces free-threading to enhance performance by allowing parallel threads without the GIL. Challenges like thread-safety and ABI compatibility are being addressed for future adoption as the default build.
Python 3.13.0b4
Python 3.13.0b4, a beta version released on July 17, 2024, offers new features like an improved interactive interpreter, JIT, and memory enhancements. Users are cautioned against using it in production.
GIL Become Optional in Python 3.13
Python 3.13 introduces an experimental feature to disable the Global Interpreter Lock (GIL), enhancing concurrency in multi-threaded applications, while allowing users to manage GIL status through various options.
500 Python Interpreters
Python 3.13 will introduce an optional Global Interpreter Lock (GIL) to enhance multithreading performance, addressing historical limitations that affected applications like video games and presenting challenges for extension developers.
What's New in Python 3.13
Python 3.13 introduces a revamped interactive interpreter, experimental free-threaded execution, a JIT compiler, removal of deprecated modules, and official support for mobile platforms, scheduled for release on October 1, 2024.
- Many commenters express skepticism about the performance trade-offs, particularly the potential 20% slowdown for single-threaded tasks.
- There is a call for better support and accessibility for JIT-enabled versions of Python, with some users feeling that compiling their own versions limits feedback from the community.
- Concerns about the complexity of multi-threading without the GIL are raised, with suggestions for automatic parallelization or better thread safety mechanisms.
- Some users reflect on past discussions about the GIL and express disappointment with the current state of Python's performance enhancements.
- There is a broader discussion about the challenges of using Python in multi-threaded environments compared to other languages.
What is the real world benefit we will get in return?
In the rare case where I need to max out more than one CPU core, I usually implement that by having the OS run multiple instances of my program and put a bit of parallelization logic into the program itself. Like in the mandelbrot example the author gives, I would simply tell each instance of the program which part of the image it will calculate.
Naturally I can easily compile my own Python 3.13 version, no biggie.
However from my experience, this makes many people that could potentially try it out and give feedback, don't care and rather wait.
The JIT does not seem to help much. All in all a very disappointing release that may be a reflection of the social and corporate issues in CPython.
A couple of people have discovered that they can milk CPython by promising features, silencing those who are not 100% enthusiastic and then underdeliver. Marketing takes care of the rest.
I wonder if that’s something they could automate? I’m sure there are some weird risks with that. Maybe a small program ends up eating all your memory in some edge case?
https://discuss.python.org/t/incremental-gc-and-pushing-back...
> What happens if multiple threads try to access / edit the same object at the same time? Imagine one thread is trying to add to a dict while another is trying to read from it. There are two options here
Why not just ignore this fact, like C and C++? Worst case this is a datarace, best case the programmer either puts the lock or writes a thread safe dict themselves? What am I missing here?
(Write single threaded code and have a compiler create multithreaded code)
https://en.m.wikipedia.org/wiki/Automatic_parallelization_to...
I spent all day not knowing whether "up the hill" meant they shipped or didn't ship. So they shipped, right? Or they shipped a JIT but removed the GIL?
You’d think certain patterns could be probably safe and the interpreter could take the initiative.
Is there a term for this concept?
Yeah right..
There’s probably a whole generation of programmers (if not two) who don’t know the feeling of shooting yourself in the foot with multithreading. You spend a month on a prototype, then some more to hack it all together for semi-real world situations, polish the edges, etc. And then it falls flat day 1 due to unexpected races. Not a bad thing on itself, transferrable experience is always valuable. And don’t worry, this one is. Enough ecos where it’s not “difficult to share data”.
Python is absolutely the worst language to work in with respect to code formatters. In any other language I can write my code, pressing enter or skipping enter however I want, and then the auto formatter just fixes it and makes it look like normal code. But in python, a forgotten space or an extra space, and it just gives up.
It wouldn't even take much, just add a "end" keyword and the LSP's could just take care of the rest.
GIL and JIT are nice, but please give me end.
Related
Free-threaded CPython is ready to experiment with
CPython 3.13 introduces free-threading to enhance performance by allowing parallel threads without the GIL. Challenges like thread-safety and ABI compatibility are being addressed for future adoption as the default build.
Python 3.13.0b4
Python 3.13.0b4, a beta version released on July 17, 2024, offers new features like an improved interactive interpreter, JIT, and memory enhancements. Users are cautioned against using it in production.
GIL Become Optional in Python 3.13
Python 3.13 introduces an experimental feature to disable the Global Interpreter Lock (GIL), enhancing concurrency in multi-threaded applications, while allowing users to manage GIL status through various options.
500 Python Interpreters
Python 3.13 will introduce an optional Global Interpreter Lock (GIL) to enhance multithreading performance, addressing historical limitations that affected applications like video games and presenting challenges for extension developers.
What's New in Python 3.13
Python 3.13 introduces a revamped interactive interpreter, experimental free-threaded execution, a JIT compiler, removal of deprecated modules, and official support for mobile platforms, scheduled for release on October 1, 2024.