News for hackers. Stuff that matters.
Re:Python stands to lose its GIL, and gain a lot of speed by gshulegaard on Sunday October 17, 2021 @07:27PM (#28900663)
Call 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).

Re:Python stands to lose its GIL, and gain a lot of speed by comex on Sunday October 17, 2021 @08:03PM (#28900850)
Perhaps better coverage on LWN:

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.

Re:Python stands to lose its GIL, and gain a lot of speed by Ph0X on Sunday October 17, 2021 @11:25PM (#28901954)
Right, the 20% boost is unrelated to the Gilectomy.

> though, as Guido van Rossum noted, the Python developers could always just take the performance improvements without the concurrency work and be even faster yet.

Why be 10% faster single threaded when you can be 20% faster single threaded!

Re:Python stands to lose its GIL, and gain a lot of speed by qeternity on Sunday October 17, 2021 @09:51PM (#28901483)
This 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.

Re:Python stands to lose its GIL, and gain a lot of speed by selcuka on Sunday October 17, 2021 @10:44PM (#28901778)
That 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-YXNBJNzfzZsD...

Re:Python stands to lose its GIL, and gain a lot of speed by qeternity on Monday October 18, 2021 @05:25AM (#28903640)
Thanks for this.

It’s interesting because I think many people (myself included) would be far more interested in the perf patches than the GILectomy.

Re:Python stands to lose its GIL, and gain a lot of speed by guenthert on Monday October 18, 2021 @01:23PM (#28908027)
Why? 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.
Re:Python stands to lose its GIL, and gain a lot of speed by vitus on Sunday October 17, 2021 @10:28PM (#28901691)
Subscriber link from Twitter if you (like me) ran into a paywall:

https://lwn.net/SubscriberLink/872869/0e62bba2db51ec7a/

Re:Python stands to lose its GIL, and gain a lot of speed by ignoramous on Monday October 18, 2021 @01:45AM (#28902597)
Re:Python stands to lose its GIL, and gain a lot of speed by thaumasiotes on Monday October 18, 2021 @01:47AM (#28902608)
> Although my experience keeps nagging at me with, "there is not such thing as a free lunch" (skepticism).

Well, yeah, someone had to make the changes. That's the cost that was paid.

You can get a mass-produced machete that is cheaper and higher-quality than a 7th-century sword. It's easy for one thing to be better than another thing across several dimensions simultaneously. That's why certain technologies go out of use -- they have negative value compared to other technologies. But that has nothing to do with the principle that there's no such thing as a free lunch.

Re:Python stands to lose its GIL, and gain a lot of speed by gshulegaard on Monday October 18, 2021 @01:15PM (#28907930)
I feel like you aren't well informed on why removing the GIL results in a single-threaded performance hit. And while I think it's always nice to keep in mind the developer effort required, it's not the only cost as GIL removal has been done before (several times, even as far back as Python 1.5 [1]).

The crux of the issue (as I understand it) is that the GIL absolves the Python interpreter of downstream memory access control. You can replace the GIL with memory access controls of various strategies, but the overhead of that access control is just that: overhead. In a multi-threaded program the concurrency gains should outweigh that overhead, but in a single-threaded one it's just extra work that wasn't being done before.

Which brings us back to no free lunch. It turns out that the claim "10%" faster without the GIL is actually a result of Gross (GIL removal author) doing a multitude of unrelated performance improvements. These performance improvements increase performance enough that the performance of single-threaded no GIL code (with overhead) is ~10% higher than today. But as Guido pointed out, the core developers could upstream the performance improvements without the GIL removal:

> To be clear, Sam’s basic approach is a bit slower for single-threaded code, and he admits that. But to sweeten the pot he has also applied a bunch of unrelated speedups that make it faster in general, so that overall it’s always a win. But presumably we could upstream the latter easily, separately from the GIL-freeing part. [2]

[1] https://docs.python.org/3/faq/library.html#can-t-we-get-rid-...

[2] https://lwn.net/ml/python-dev/CAP7+vJJ1hzXiyDwVs6-eXed+DtodH...

Re:Python stands to lose its GIL, and gain a lot of speed by thaumasiotes on Monday October 18, 2021 @03:27PM (#28910349)
> he has also applied a bunch of unrelated speedups that make it faster in general

Tell me how "faster in general" doesn't make you suspicious about a free lunch.

Re:Python stands to lose its GIL, and gain a lot of speed by gshulegaard on Monday October 18, 2021 @06:06PM (#28912415)
To be explicit, I was skeptical because I believed that GIL removal requires adding overhead for managing memory access. Having dug a bit deeper into it that seems confirmed. The proposed GIL removal strategy _is slower for single-threaded code_ like other solutions before it. It turns out the reported performance increase was the result of orthogonal performance improvements overshadowing the overhead of GIL removal.

Put another way, if the performance improvements were upstreamed without removing the GIL the resulting performance increase would be ~20% instead of just ~10%. Which is what Guido was getting at in the quote I cited. Assuming the benchmarks to be true for the moment, this means that removing the GIL on this PoC branch is a 10% performance hit to single-threaded workloads.

Re:Python stands to lose its GIL, and gain a lot of speed by atoav on Monday October 18, 2021 @01:12AM (#28902421)
> "there is not such thing as a free lunch" (skepticism).

When you carry a heavy suitcase filled with lead and you drop it, things get lighter for free. You paid for it by carrying the damn thing around with you for the whole time.