14 ms·
GIL Become Optional in Python 3.13
- allanren 2y agoIt's good to see Python finally able to get rid of GIL. Looking forward to see how much performance can it improve.
- fastball 2y agoWe already know the upper bound of perf improvement – existing perf * number of cores. It will be worse than that though, as all the GILectomy plans make single-threaded performance worse. So if you're expecting something better than that, you will be disappointed.
- vlovich123 2y agoAll the GILectomy plans IIRC also include single threaded performance improvements to offset any such costs. So while performance vs GIL is maybe worse for single threaded for the same Python version, performance will still be ahead of where it is today for single-threaded python (assuming everything goes according to plan). That's also why multi-threaded performance will be more than just existing perf * number of cores (vs what it is today, not what removing the GIL alone provides).
- eviks 2y agoBut it doesn't offset anything since you get all the other improvements anyway, they're not tied to gil/nogil
- vlovich123 2y agoI could be misremembering, but I thought that the MSFT team proposed those performance improvements specifically to offset any concerns about single threaded performance degradation from removing the GIL. Thus even if development is happening in parallel by independent (which I thought it wasn't - I thought it was all 1 team doing this work), it was predicated upon nogil being accepted in the first place. Thus if GIL were to remain in Python, then this performance work wouldn't be happening.
- eviks 2y agoMaybe the work wouldn't be happening without the noGIL work, but once it's happened it's not tied to the GIL, you can pick those improvements and continue with a GIL-only Python
- vlovich123 2y agoThis post is literally about step 1: add this behind an unsupported experimental flag to get more insights. Step 2 is mid-term to make it a supported option based on readiness (within another 2 years). Step 3 is making it the default & then removing the GIL [1]. Steps 2 and 3 may not happen if some major unsolvable obstacle appears. But I doubt it's going to be so easy to reverse this direction. Given MSFT is driving all of this right now, it's hard to imagine there's going to be much appetite to break their trust; MSFT is more likely to cut funding before completion which would create some chaos than the steering committee is to violate an agreement around funding (MSFT has made specific long term commitments they're going to keep, but those commitments are only for a few years IIRC). [1] https://developer.vonage.com/en/blog/removing-pythons-gil-its-happening https://developer.vonage.com/en/blog/removing-pythons-gil-it...
- Sakos 2y agoWhy is MSFT so interested in funding this?
- robertlagrant 2y agoMSFT are keen to invest in popular development tools such as Python, Javascript, and Git. They hired Guido; they bought NPM; they bought GitHub. I don't know what the plan is, but they haven't succeeded (outside of the corporate world, really, for C# and the functional world in F#) in making modern tooling and languages people want to use.
- skeledrew 2y agoIf you have too steep a hill making inroads into a desired community, and there's enough money, just buy the thing that brings said community together.
- logicchains 2y agoThe GIL causes a huge performance hit in data processing/ML by forcing the use of multi-process, which leads to a bunch of unnecessary copying of memory between processes unless you put in a bunch of effort to explicitly share memory. So in some cases the savings will be gigantic, from no longer unnecessarily copying huge dataframes between processes.
- antupis 2y agoBut usually, in spaces where you need speed Python is just an orchestrator or glue between pipelines, and actually, calculations are done by db or some c/c++/fortran library.
- logicchains 2y agoYes pandas/numpy calls C++ to do calculations efficiently, but the "glue" can still introduce significant slowdown relative to that when it's copying tens of gigabytes of dataframe unnecessarily between processes. Of course that slow part itself could also be moved to C++, but that's much more effort then just parallel mapping over the dataset in Python with no copying/multiprocessing, as will be possible with no-gil.
- aragilar 2y agoBad code/quick hacks will always be slow (but can be great for prototypes), and sometimes it's worth planning how you're going to process something rather than piling on multiprocessing. Once you reach the point of multigigabyte IPC, it's worth spending the time doing it right.
- robertlagrant 2y agoBuilding libraries on a GIL-less Python would enable people to access that power without them all building it from scratch themselves.
- 2y ago
- hyperbrainer 2y agoI would use python much more if every version did not have these many breaking changes, especially with the removal of the GIL. Shame they did not learn from 2 to 3.
- Narhem 2y agoAwesome to see Python turning more into a full fledged programming tool. Would be neat to see some kind of static typing, or atleast enforced duck typing.
- daniel-s 2y agoDo you mean like mypy and optional type hints or something different, enforceable like Typescript?
- fastball 2y agoI wouldn't really say Typescript is enforceable, given that the types aren't actually considered at runtime.
- pjmlp 2y agoIn fact, people should see Typescript as a linter / bundler tool than a programming language by itself, ignoring the design mistakes of how enums and namespaces came to be.
- pyrale 2y agoThat is the case for most typesystem considered safe, save for introspection use cases. For instance, haskell, a language with strong type guarantees, does erase types for runtime.
- School-Cotton 2y agoAlmost no languages have types considered at runtime.
- guappa 2y agoWell python does, after the famous PEP to pack all types into strings got parked (probably forever). There's packages to typecheck at runtime, even to check the parameters to a function.
- deleted 2y ago
- andy_xor_andrew 2y agoWill -—disable-gil ever be the default that should be targeted by everyone? Or will python have “requires-gil” libraries and “allows-no-gil” libraries?
- boristsr 2y agoYeah it will be the default in the future. They laid out their roadmap a while go. It's a long roadmap to allow libraries to update. IIRC it would be default by 3.16 at the earliest. I think there was even a stage where there would be GIL and GILless distributions. https://www.infoworld.com/article/2338862/python-moves-to-remove-the-gil-and-boost-concurrency.html https://www.infoworld.com/article/2338862/python-moves-to-re...
- surfingdino 2y agoGlad to see it, but it's early days and care is needed when porting existing code or writing new. There's also question of modules. Will those get updated? I am expecting a slow migration over the next couple of years. Python has made me money for over 15 years, but if I want to write code that can use all those cores and threads I use Golang.
- mort96 2y agoI kind of have the opposite feeling of many other people here... to me, Python is already pretty much perfect for my use, which is things like build scripts and random tools I make, plus it's used by a bunch of software I need to compile. The one big problem it has is that it keeps changing. I'll try to compile some dependency that I haven't updated in some time and I'll find that it fails to build because Python changed in some backward incompatible way. Or a tool I made will suddenly start printing deprecation warnings because Python has deprecated a library. I get that for people for whom Python is their main language, all these changes make their lives better. But for me it kinda just gets in the way. Personally, I wish Python would continue to be maintained as is, but stop changing so much. Stop breaking my builds.
- Elucalidavah 2y ago> The one big problem it has is that it keeps changing What prevents you from using an old Python version?
- dijit 2y agoUsually us plebs use the system python. With no python version manager (I don’t even know any off the top of my head). Also virtualenvs only get you so far, I’ve come back to many projects on my machine with broken virtualenvs, I guess due to some dynamically linked dependency of python that my system no longer has. :(
- ok_dad 2y ago> With no python version manager (I don’t even know any off the top of my head) Try a tool called `pyenv`. It's pretty great. I pair it with the package manager called `poetry`.
- Joeboy 2y agoOr https://github.com/astral-sh/uv https://github.com/astral-sh/uv can replace both. Various features are tagged as "experimental", and I guess the api might change, but it seems to work already. I have high hopes for it eventually making python's fragmented package management issues go away. Edit: Somebody's going to respond with the XKCD aren't they? I know about the XKCD and I nevertheless have high hopes for `uv`.
- ustad 2y agoThere is a certain beauty with the GIL and without it there will be more unnecessary complexity for the 80% of applications in the future and potential maintenance issues for current software. To also enable this as default in the coming years is crazy. I would love to hear what Guido thinks about this.
- guappa 2y agoHe's ok with all the breaking changes I think, from what I can see on the python forum.
- IshKebab 2y agoPython 3.12 had a ton of breaking changes too so that doesn't surprise me. They clearly didn't learn from the Python 3 experience! Or maybe they did and their lesson was "still make breaking changes but just don't change the major version number".
- guappa 2y agoYes I think that was their takeaway, so now instead of having a slooooow migration we just have tens of libraries that break at every python update. Also there's no way to get access to pypi and fix the abandoned libraries. So they get patched in distributions and remain broken forever on pypi.
- smcin 2y agoWhich libraries are you claiming break at every Python update? (3.12 or later)
- ChrisRackauckas 2y agoThe last updates deleted modules from the standard library like distutils. Any library that used those modules is now broken.
- pycomrade 2y ago[flagged]
- Y_Y 2y agoI was with you right up until the last sentence. Is the GIL really a "political" issue?
- entropyneur 2y agoWhy are people building their software in Python when they need performance? There are other languages that excel at this. Python strengths lie elsewhere and they are increasingly being diminished with all these "upgrades". Splitting the ecosystem with async was already a major blow and now we are looking at another split along gil/non-gil axis. It's just sad.
- Irishsteve 2y agoMostly projects / products that start off with very low usage thus python is perfectly fine (Why overoptimize). And then it becomes useful - and a rewrite isn't worth it.
- graemep 2y agoYou can then rewrite performance critical bits in a fast language. Much Python usage is a result of people making use of this.
- zarzavat 2y agoHow is that Python’s problem though? If you paint yourself into a corner by choosing the wrong language then eat the rewrite or eat the hardware costs. There was a consensus after the Python 3 debacle of “No major breaking changes”. We seem to have lost that because of moneyed interests and that’s sad.
- emblaegh 2y agoThat's such a strangely distorted world view. If a car company releases a, idk, trunk-extension in response to customer feedback would you go "How is this Ford's problem? If you didn't think about the trunk size eat the loss and buy a new car" ? Python developers want python to remain useful to the developers who want to keep using the language. It's not an incomprehensible motivation.
- zarzavat 2y agoIf I attach something to my car it doesn’t affect your car. Who does no-GIL benefit? For the majority who use Python for single threaded code, no-GIL will make their code slower because a thread-safe interpreter is always going to be slower than one that can assume ST operation. For the minority who want parallelism, there’s two other options: OS processes and subinterpreters. If you can use either of these then you will get better performance with a GIL for the same reason. So no-GIL will only be faster for a minority of a minority who want parallelism but can’t use OS processes or subinterpreters. Meanwhile everybody else writing libraries has to make sure that their code is no-GIL safe, to support this tiny minority, and if no-GIL ever becomes default then everybody else has to do something to turn it off. It’s such a stupid idea.
- XorNot 2y agoExciting! I'm going to be locking all my projects to --no-gil or whatever and targeting 3.13 by default as soon as possible. Everytime I've needed just a bit of multicore performance and have gotten stuck using multiprocessing sucks - I'd much prefer just to use threading and not worry about the pickling process.
- marker10 2y ago[flagged]
- logicchains 2y agoI'm really looking forward to PyTorch supporting this as it'll make writing custom dataloaders way easier, being able to use multiple threads directly rather than having to deal with all the wierd edge cases and copying that comes with multiprocessing.
- aardvark179 2y agoThe world needs both more and less concurrency FUD. It needs more because too many people think their libraries are safe due to things like the GIL when they likely have bugs that will occur occasionally, and it needs less because that belief makes people terrified that removing the GIL will break their code. If your pure Python code fails without the GIL it can probably fail with the GIL, and testing it without the GIL might help you find those bugs a lot quicker.
- robertlagrant 2y ago> If your pure Python code fails without the GIL it can probably fail with the GIL No, if you remove the GIL there is a whole class of bugs that will appear in code that was safe with the GIL in place.
- spacechild1 2y agoFor example? I don't think the GIL affects the behavior of pure python code.
- robertlagrant 2y agoYeah. You're right. It guards some CPython internals, but I don't think it does affect code the way I thought it did. Thanks for the prompt to investigate.
- jokoon 2y agoI wonder if I will see Python as a browser scripting language in my lifetime
- skeledrew 2y agohttps://pyscript.net https://pyscript.net
- tgz 2y agoAfter GIL they must add Result/Option and drop exceptions.
- anticensor 2y agoIn Python, exceptions are effectively free, unlike JVM or .NET. Every for loop in Python relies on those exceptions.