News for hackers. Stuff that matters.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by axblount on Monday June 06, 2022 @11:37AM (#31641842)
I hope Sam Gross's no-GIL changes are adopted. It would be amazing to have full multithreaded concurrency in python.

https://mail.python.org/archives/list/[email protected]/...

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by albertzeyer on Monday June 06, 2022 @01:50PM (#31643498)
https://news.ycombinator.com/item?id=28880782 https://news.ycombinator.com/item?id=29005573 https://news.ycombinator.com/item?id=31348097

Note that Sam's no-GIL changes are not only about the removal of the GIL (although that was the main goal). There are a number of other unrelated improvements to make it faster. And as far as I know, most of those unrelated improvements have gotten into CPython now.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by rat87 on Monday June 06, 2022 @02:44PM (#31644129)
I'm worried about it. My understanding is that the GIL removal was still slower then with GIL, but that he added useful unrelated speedups to compensate. If the speedups get into 3.11 but no gil doesn't will they accept a significantly slower 3.12?
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by __d on Monday June 06, 2022 @08:12PM (#31648245)
Yeah, I'm worried too.

It seems like the core team doesn't share my sense that nogil is the single most important thing that Python needs to do in a world of many-core processors. If nogil is now blocked because it's deemed an unacceptable performance hit vs 3.11, I'll be very, very disappointed.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by O5vYtytb on Monday June 06, 2022 @11:04PM (#31649416)
Most python code in the world is currently single threaded. It makes sense to me to start with the low hanging fruit that affects the majority of existing code and then move on to harder problems.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by __d on Tuesday June 07, 2022 @05:55AM (#31651954)
Sure, but Guido put a pre-condition on GIL removal years ago that it must not cause single-threaded code to suffer a performance penalty.

So Sam came up with a way to ensure that (on balance, if not in every example), we could have same-or-better performance and no GIL. Awesome!

But now we're getting the performance boosts without the GIL removal, and so in the next release, the GIL removal will cause a performance regression unless we can somehow find more performance boosts. It feels like this could just happen forever.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by O5vYtytb on Wednesday June 08, 2022 @09:36AM (#31667116)
There's many more improvements to be made in single threaded performance, including things like JIT. Future improvements are complicated, they won't be a free lunch like this first round has generally been. My feeling is that things like JIT and nogil will start out as optional and work their way into the ecosystem over time where the performance implications are less severe for the general use case.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by zackees on Tuesday June 07, 2022 @01:13AM (#31650127)
Why? Python gives you the ability to spawn processes so there's always an escape hatch for building multi-core code.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by __d on Tuesday June 07, 2022 @05:51AM (#31651923)
Right. But as you implicitly note, it's a work-around ("escape hatch"), not a feature.

eg. Unix had processes from day 1, but threads were added (with significant effort) because threads are a better abstraction for addressing lot of problems. Especially so when your CPU has lots of cores.

The work to make multiprocessing better is certainly useful, and valuable, but it's still a work-around.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by jacob019 on Monday June 06, 2022 @03:45PM (#31645159)
It might make sense to have runtime configuration that enables no-GIL mode, or just enable it automatically when importing threading, so that non-threaded workloads don't suffer.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by O5vYtytb on Monday June 06, 2022 @11:03PM (#31649403)
The faster cpython project isn't done after 3.11. they're working on many other improvements for 3.12 and we'll see other things possibly a JIT or at least an API to facilitate accelerators in 3.13+

I'm not worried about a lack of single thread performance increases for some time.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by btown on Monday June 06, 2022 @12:27PM (#31642494)
Quick link to the (incredible) design doc linked in the first post there: https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsD...
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by skrause on Monday June 06, 2022 @12:49PM (#31642800)
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by bratao on Monday June 06, 2022 @12:05PM (#31642221)
I really wish this project didn't die, this would open to so many use-cases. I hate to use multi-process to scale my projects.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by matsemann on Monday June 06, 2022 @12:14PM (#31642334)
Yeah, while it in some regards is nice having multiple small deployments of our python app than can be scaled up and down independently, it's sometimes such an hurdle to something "extra" in a smaller app. Have a simple webserver and want to do some things out of band? In jvm I would use a concurrent queue and add tasks to it, and spin up some threads consuming that. In python you either spin up a new process and deal with the communication problems, become a master of greenlet and python internals, or most likely default to celery which need it's own deployment.

It sometimes boggles my mind how python is considered the quick and easy way for startups, while at the same time doing trivial things become such a hurdle.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by throwaway894345 on Monday June 06, 2022 @01:38PM (#31643348)
> Have a simple webserver and want to do some things out of band? In jvm I would use a concurrent queue and add tasks to it, and spin up some threads consuming that. In python you either spin up a new process and deal with the communication problems, become a master of greenlet and python internals, or most likely default to celery which need it's own deployment.

This is probably risky in production anyway, because the load balancer (typically) has no insight into these background tasks and will happily kill a process/pod/etc that is running a background process. You should probably dispatch the workload to an external task runner (e.g., Lambda or a Kubernetes Job or similar) unless you really don't care if the background task gets killed mid-flight. (I've had a few dev teams ignore these warnings and then blame infrastructure when their background jobs got killed mid-flight occasionally).

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by matsemann on Monday June 06, 2022 @02:26PM (#31643935)
Yes, that is true. My case here was about pushing some metrics somewhere, where losing some weren't an issue, but I didn't want to block main thread doing it.

But this single java app on some EC2 instance could do what you need 10 "apps" and possibly a complicated k8s deployment to handle with python. Some just because the raw performance of python is far worse, but most of it because of cases like this, where simple things can't be shared. So lots of unnecessary complexity compared to "old and verbose" java.

Another example is prometheus metrics. The current app I'm working on doesn't have a webserver. Which makes it really awkward in python to add prometheus. Since adding an endpoint to my app creates a new process and needs to be deployed almost as a sidecart, there is no smooth way to actually get the metrics from my main app to the endpoint that can be scraped since they don't share the same process.

Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by ledauphin on Monday June 06, 2022 @12:46PM (#31642770)
it's a huge hurdle in any scenario where you have large, static dataset from which you want to derive computation-heavy results. Multiprocessing generally requires making copies of that data, which can be impossible. The workarounds (e.g. mmap) take an order of magnitude more engineering effort.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by dekhn on Monday June 06, 2022 @12:58PM (#31642906)
I agree 100% (I come from a "use all the cores with threads and shared memory to get linear speedups on many workloads" world). But I think at this point the python leadership has committed to the "every time the GIL-removal looks plausible, find some more single-core speedups to stave off the change". Put another way: I've given up on the hope that python will ever multicore the way I think it should multicore.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by throwaway894345 on Monday June 06, 2022 @01:42PM (#31643409)
I'd be tickled if Python would singlecore the way I think it should singlecore. Unfortunately, it remains considerably slower even than JavaScript (never mind Go, Java, etc). A lot of bad choices that can't easily be undone without breaking compatibility for a handful of packages, and the Python leadership seems unable or unwilling to guide the community through those changes.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by onox on Monday June 06, 2022 @01:52PM (#31643527)
I had a similar problem last month where I needed to compute some results on multiple datasets (with a little bit of concurrency per dataset). In the end I just ported the code to Ada which makes it very easy to create task hierarchies. You can define variables of task types on the 'stack' and the program leaves the enclosing block when the variables can go out of scope after every task has finished. I can now easily put all cores to maximum use. The list comprehensions in Python became a little bit more verbose though because I had to use an older revision (2012) instead of the new 2022 revision.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by orm on Monday June 06, 2022 @10:11PM (#31649093)
Have you checked out the Ray library? I use it for this type of scenario and it works well, without as much effort as it would take otherwise.
Re:Python 3.11 Performance Benchmarks Are Looking Fantastic by d0mine on Monday June 06, 2022 @03:54PM (#31645284)
SharedMemory is a part of the multiprocessing module