5 ms·
Losing the GIL strictly makes the language strictly more flexible. Previous GILectomies tanked performance to an unacceptable degree. In single-threaded code,
by klyrs 5y ago
Losing the GIL strictly makes the language strictly more flexible. Previous GILectomies tanked performance to an unacceptable degree. In single-threaded code, this one is a moderate performance improvement in some benchmarks, and a small detriment in others -- which is about as close to perfect as one could expect from such a change. That's why people are excited about it.
At a higher level, Python is getting serious about performance. But this gives both flexibility and performance.
- aeturnum 5y agoYah, that's definitely the future I'm hoping for. What I am worried about are the kind of transition issues I mentioned. Python 2 -> 3 strictly made the language more flexible too - but the Python ecosystem is about existing code almost more than the language and I worry that we could find similar problems here. Potential for plenty of growing pains while chasing relatively small gains.
- ynik 5y agoIn the company I'm working for, we had to spent more engineer time on GIL workarounds (dealing with the extra complexity caused by multiprocessing, e.g. patching C++ libraries to put all their state into shared memory) than we needed for the Python 2 -> 3 migration. And we've only managed to parallelize less than half of our workload so far. Even if this will be a major breaking change to Python, it'll be worth it for us.
- gshulegaard 5y agoCall me optimistically skeptical. I share similar reservations about GIL obsession with the original comment author, but if this is true: > The overall effect of this change, and a number of others with it, actually boosts single-threaded performance slightly—by around 10% Then it sounds like having the cake and eating it too (optimism). Although my experience keeps nagging at me with, "there is not such thing as a free lunch" (skepticism).
- comex 5y agoPerhaps better coverage on LWN: https://lwn.net/Articles/872869/ https://lwn.net/Articles/872869/ The no-GIL version is actually about 8% slower on single-threaded performance than the GIL version, but the author bundled in some unrelated performance improvements that make the no-GIL version overall 10% faster than today's Python.
- qeternity 5y agoThis suggests that the unrelated patches improve perf by 20% (0.92 * 1.20 ~= 1.10) I would love to be proven wrong but I am skeptical.
- selcuka 5y agoThat is already explained by the author [1]: > The resulting interpreter is about 9% faster than the no-GIL proof-of-concept (or ~19% faster than CPython 3.9.0a3). That 9% difference between the “nogil” interpreter and the stripped-down “nogil” interpreter can be thought of as the “cost” of the major GIL-removal changes. [1] https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsDFosB5e6BfnXLlejd9l0/edit https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsD...
- qeternity 5y agoThanks for this. It’s interesting because I think many people (myself included) would be far more interested in the perf patches than the GILectomy.
- guenthert 5y agoWhy? It's not like CPython is a speed daemon. I'd think there are some low hanging fruits, simply because performance is such a low priority for the maintainers. It doesn't even do TCO after all.
- vitus 5y agoSubscriber link from Twitter if you (like me) ran into a paywall: https://lwn.net/SubscriberLink/872869/0e62bba2db51ec7a/ https://lwn.net/SubscriberLink/872869/0e62bba2db51ec7a/
- xiaodai 5y agoGIL will improve performance of multi-threaded code but the issue with Python performance is single-threaded code and its rich object system. Can't see Python getting there unless we go to Python 4 which, given the fiasco that was Python 2->3 is probably never gonna happen. Might as well wait for Julia to improve its TTFP then to hope for a Python 4.
- native_samples 5y agoWell, CPython probably won't ever get there. But Python as a language maybe could. The GraalPython implementation of Python 3 is built on the JVM, which is a fully thread safe high performance runtime, and Graal/Truffle provide support for speculation on many things. For pure Python it provides a 5-7x speedup already and the implementation is not really mature. Although at the moment they're working on compatibility, in future it might be possible to speculatively remove GIL locks because you have support for things like forcing JITd code to a safepoint and discarding it, if you want to change the basic semantics of the language.
- salawat 5y agoThis is different from Jython, correct?
- native_samples 5y agoIt's sort of taking Jython's implementation approach to a much greater extreme, and bypassing bytecode, so it isn't limited by the Java semantics anymore. It resolves a few big problems Jython had: - GraalPython is Python 3, not Python 2 - It can use native extensions that plug into the CPython interpreter like NumPy, SciPy etc. The C code is itself virtualized and compiled by the JVM!
- salawat 5y agoNeat! Now that I've gotta check out!
- 5y ago
- birdyrooster 5y agoPython needs to be compiled into machine language to ever have a chance of competing on speed. We can already get around the GIL with multiprocess but Python is still to slow even when not bound by copying memory between processes.
- Ph0X 5y agoI don't think the goal is to "compete on speed", but I'm sure people wouldn't complain about their Python scripts running 15x faster on their 16 core CPU. And it is also about flexibility. What I love about Python is the simplicity, and let's be honest, multiprocess anything but. Especially if you fall into one of the gotchas (unpickable data for example).
- birdyrooster 5y agoMultiprocess is quite easy, have you tried aio_multiprocess?
- saghm 5y agoThe phrase "competing on speed" begs the question "competing...with what?" If the answer is "machine compiled languages", then yes, it's unlikely Python will ever match their speed without also being compiled to machine code, but there are plenty of other interpreted languages with better performance than Python (even ruling out stuff like Java that technically isn't "compiled into machine language" in the way that phrase usually would mean); lots of work is done on JavaScript interpreters to improve performance, and I don't think that specifically has cost the language much flexibility.
- nextaccountic 5y ago> other interpreted languages Both Java and Javascript are ultimately compiled into machine code, through JIT. And this matters because Python doesn't have JIT. Even Ruby, that is historically a way slower language, is gaining JIT nowadays. Python has got no excuses.
- acomjean 5y ago