5 ms·
Is there some headline reason for these improvements? I remember reading about the GILectomy, and how actually many of the improvements, aimed at making GILect
by rich_sasha 4y ago
Is there some headline reason for these improvements?
I remember reading about the GILectomy, and how actually many of the improvements, aimed at making GILectomy feasible, make single-threaded Python runs faster too. There was even the trepidation that PSF might accept these changes, but still say no to GILectomy. Is this at all related?
- bpicolo 4y agoMicrosoft is funding the work with Mark Shannon / GVR / Eric Snow. The project is called "Faster Cpython". Pretty excited for the 3.12 work, where they plan to introduce JIT compilation I believe? I'm not sure about the progress on the new form of GIL removal, but as far as I've seen it's a separate effort. https://github.com/faster-cpython/ https://github.com/faster-cpython/ https://www.theregister.com/2021/05/13/guido_van_rossum_cpython_3_11/ https://www.theregister.com/2021/05/13/guido_van_rossum_cpyt...
- Alex3917 4y ago> Pretty excited for the 3.12 work, where they plan to introduce JIT compilation I believe? "A JIT, according to Shannon, will probably not arrive until 3.13 at the earliest, given the amount of lower-hanging fruit that is still to be worked on. The first step towards a JIT, he explained, would be to implement a trace interpreter, which would allow for better testing of concepts and lay the groundwork for future changes." https://pyfound.blogspot.com/2022/05/the-2022-python-language-summit_2.html https://pyfound.blogspot.com/2022/05/the-2022-python-languag...
- KptMarchewa 4y agoRemoving GIL naively would decrease single thread performance. Every project aiming at removing GIL failed because it could not get performance comparable with GILed Python.
- sumtechguy 4y agoRemoving the GIL is an idea (and as you point out not working very well). When optimizing do not depend on 'that one cool trick' to fix everything. In this case it looks like they are removing extra work and doing work once and keeping a copy around (caching).
- rich_sasha 4y agoSam Gross worked on this, this made rounds recently in Python user world: https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsDFosB5e6BfnXLlejd9l0/edit https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsD... It's a fork of Python 3.9, takes out GIL and introduces optimisations to speed up both single- and multi-threaded execution (since the bar set by PSF is that no-GIL implementations must be at least as fast as GIL single threaded programs). He ends up with a net 10% speed improvement. If he does these optimisations, and also doesn't remove the GIL, the performance boost is even larger. So, depending on how you look at it, it's either: - A bunch of optimisations, plus a GILectomy which slows Python down, or - A bulk change that removes GIL and speeds things up Since these improvements were in a similar ballpark, my fear was that the improvements are taken off the branch, with GIL left in place...
- riyadparvez 4y agoWhy would it decrease single thread performance? How is python different than other languages that support native full-fledged multi-threading, eg Java, Go, C#?
- adgjlsfhk1 4y agopython made it's C api visible, so things like reference counting are widely observed by C libraries that interop with python. This makes it much harder to make changes since you can't change the implementation in ways that programs rely on.
- kortex 4y agoA big part is that Python uses reference counting GC. Java, Go, C# all use tracing GC. Py_INCREF and Py_DECREF are responsible for inc/decreasing the reference count, and are not atomic. The GIL ensures refcount safety by allowing only one thread access to changing refcount. The naive approach to parallelization would require locking each ref inc/dec. There are some more sophisticated approaches (thanks to work by Sam Gross et al) that avoid a mutex hit for every inc/dec. Tracing GC does not run into this problem. Why Python doesn't use tracing GC is not something I am qualified to answer. Sam Gross' work: https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsDFosB5e6BfnXLlejd9l0 https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsD... The GIL code: https://github.com/python/cpython/blob/main/Python/ceval_gil.h https://github.com/python/cpython/blob/main/Python/ceval_gil... Py_INCREF: https://github.com/python/cpython/blob/a4460f2eb8b9db46a9bce3c450c8b038038a7c93/Include/object.h#L493 https://github.com/python/cpython/blob/a4460f2eb8b9db46a9bce...
- kaba0 4y agoI am by no means knowledgeable enough on the topic, but Swift has similar problem domain, and afaik only uses atomic ref counts for objects that “escape” from a given thread - is there a reason something like that wouldn’t work for python as well?
- theandrewbailey 4y agoAt this point, I've given up hope that CPython will ever lose the GIL. The best we can hope for is having multiple interpreters[0], each with their own GIL[1]. [0] https://peps.python.org/pep-0554/ https://peps.python.org/pep-0554/ [1] https://github.com/ericsnowcurrently/multi-core-python/issues/79 https://github.com/ericsnowcurrently/multi-core-python/issue...
- Spivak 4y agoFor absolutely critical hot path code this obviously won’t be enough but subinterpreters with memory arenas is a really solid model for safe concurrency and faster than multiprocess IPC.
- digisign 4y agoThe reason is that a lot of folks complain Python is slow. It can be 100x slower than optimized C at times. Are these projects related? No, except that they are being attempted in the same time frame and may complement each other.