Larry Hastings - Removing Python's GIL: The Gilectomy - PyCon 2016
PyCon 20165 HN recommenders · recommended in 5 months, 2016-2023
49K views · 10 years ago · talk · dated
Larry Hastings explains what Python's GIL is, what problems it solves and how it works, and presents his Gilectomy project to remove it, including the performance and C-extension obstacles.
The default reference in Python performance threads for why removing the GIL is hard.
46:10Understanding the Python GIL
David Beazley
127K views • 14 years ago
1:13:53Raymond Hettinger, Keynote on Concurrency, PyBay 2017
SF Python
161K views • 9 years ago
59:11How to Speed up a Python Program 114,000 times.
InfoQ
171K views • 13 years ago
40:34Charlie Marsh: uv: An Extremely Fast Python Package Manager
Jane Street
107K views • 2 years ago
42:44Armin Ronacher - A Python for Future Generations
EuroPython Conference
6K views • 9 years ago
34:55"Outperforming Imperative with Pure Functional Languages" by Richard Feldman
Strange Loop Conference
98K views • 5 years ago
47:34RailsConf 2011: Aaron Patterson, "Double Dream Hands: So Intense!"
O'Reilly
26K views • 15 years ago
57:05Keynote: Begin...End?
David Beazley
9K views • 5 years ago
22:41"Clean" Code, Horrible Performance
Molly Rocket
1.2M views • 3 years ago
1:24:39Mojo Lang - Tomorrow's High Performance Python? (with Chris Lattner)
Developer Voices
64K views • 2 years ago
49:55How Python was Shaped by leaky Internals, Armin Ronacher, Flask framework
Видео с мероприятий {speach!
20K views • 10 years ago
28:34RailsConf 2016 - Rails to Phoenix by Brian Cardarella
Confreaks
12K views • 10 years ago
52:40Keynote. Professor Steven G. Johnson | JuliaCon 2019
The Julia Programming Language
18K views • 7 years ago
3:15:51Guido van Rossum: Python and the Future of Programming | Lex Fridman Podcast #341
Lex Fridman
1.8M views • 3 years ago
1:01:45A Talk Near the Future of Python (a.k.a., Dave live-codes a WebAssembly Interpreter)
David Beazley
26K views • 7 years ago
1:17:07Alexis King - “Effects for Less” @ ZuriHac 2020
Zürich Friends of Haskell
25K views • 6 years ago
1:01:04Introduction to Julia - Part 1 | SciPy 2014 | David Sanders
Enthought
80K views • 12 years ago
26:34Shared memory parallelism in Julia | Kiran Pamnany | Cambridge Julia Meetup (May 2018)
The Julia Programming Language
7K views • 8 years ago
30:37High-performance Tree Wrangling, the APL Way // Aaron Hsu // Dyalog '18
Dyalog User Meetings
6K views • 7 years ago
1:02:44Chris Seaton @ VMSS16: JRuby+Truffle: Why it’s Important to Optimise the Tricky Parts
softdevteamuk
5K views • 10 years ago
11 comments from Hacker News
There's a great talk by David Beazley (I don't remember which one) that he basically explains that removing the GIL isn't difficult at all. After all, it's just one lock. The issue is all the libraries and packages that were built around it. It's now been YEARS of building on top of the GIL. So anyways, PEP 703 is a a nice effort, but I doubt we (everyday mortals) can enjoy it. Meta, and big companies with a specialized team might be able to exploit it by making sure their entire stack is GIL-free. EDIT: My bad, the talk is from Larry Hastings: ▶ this video
In addition to the points other people raised, "simply" removing the GIL by changing the current reference-counting GC to do atomic reference updates will also substantially reduce single threaded performance; there was a PyCon talk about that. ▶ this video See also Swift for another language whose implementation has performance issues caused by ubiquitous atomic reference counting.
▶ this video Or search “gilectomy” on LWN. Or check out stackless etc.; it turns out removing the GIL technically is historically one of the easier parts of removing the GIL entirely. It sounds like your main problem is with python’s GC model. Reference counting doesn’t have to be thread-unsafe, but in scripting/interpreted-ish languages that want their threading story to involve seamless (I.e. no special syntax unless you want it, it’s on you not to blow off your foot) sharing of state between threads at will, like Python and Ruby, a GIL or equivalent is the norm. Sometimes it’s not as intrusive as python’s, but it does seem like a necessary (or at least very likely) implementation pattern for languages that want to provide that seamlessness. You can have thread-safe reference counted GC in a traditional scripting language, but that tends to come with a much less automatic threading/concurrency API. Perl 5 is an example of that category, and it is implemented in C.
I feel like the GIL is, at this point, Python's most infamous attribute. For a long time I thought it was also the biggest flaw with Python...but over time I care less and less about it. I think the first thing to realize is that single-threaded performance is often significantly better with the GIL than without it. I think Larry Hasting's first Gilectomy talk was extremely insightful (about the GIL in general and about performance when removing the GIL): ▶ this video I am not sure I would, personally, trade single-threaded performance for enabling multi-threaded applications. I view Python as a high-level rapid prototyping language that is well suited for business logic and glue code. And for that type of workload I would value single-threaded performance over support for multi-threading. Even now, a year later, the Gilectomy project is still slightly off performance-wise (although it looks really really close :) ): link As noted elsewhere, multi-processing offers adequate parallelization for this type of logic. Also, coroutines and async libraries such as gevent and asyncio offer easily approachable event loops for maximizing single-threaded resource utilization. It's true that multi-processing is not a replacement for multi-threading. There definitely are tasks and workloads where multi-processing and its inherent overhead make it unsuitable as a solution. But for those tasks, I question whether or not Python itself (as an interpreted, dynamically typed language) is suitable.
Larry Hastings - Removing Python's GIL: The Gilectomy - PyCon 2016 ▶ this video (I'm pretty sure this is the video I'm thinking of) It's 30m, but worth it if you're interested. Not sure what progress has been made since then.
Just to add more context for others... C extensions called from Python are still subject to the GIL of the calling interpreter[1]. In fact, this guaranteed thread safety has led to the creation of many non-thread safe Python C extensions which is now a critical blocker to efforts to removing the GIL[2], although there are also a number of other issues as well. As noted in the StackOverflow, you can release the GIL but there are some tricks to doing so safely[3]. But threads of a C extensions library are not necessarily pinned to a single core by the GIL like regular Python byte code. Although many performance oriented libraries like numpy[4] forsake multi-threading by default in many cases and rely on parallelization by the user (programmer)[5]. [1] link [2] ▶ this video [3] link [4] link [5] link
Python has made some trade-offs that you dislike. You complain about the negative consequences without comparing those against the benefits. One of the major factors in speed is efficient memory layout. Contrast a Python list with a NumPy array. To achieve speedier loops and vectorized arithmetic [0], the array gives up dynamic typing and dynamic sizing. In most applications, I would gladly give up some compute speed to gain some programming productivity. I love duck-typing. Formal typing has some impressive examples, but in the projects I've worked on has reduced my productivity. Perhaps because data are so often serialized to simple formats or written to databases that discard the best tools of formal typing. Anecdotal evidence, for sure. I've never been bothered by the GIL, but I have benefitted from it [1]. [0] link [1] ▶ this video
To be fair, the GIL was included (AFAIK) because it was simple to implement. Also, Guido has said (2007) [1] that he would welcome a patch to remove the GIL if...: > "... I'd welcome a set of patches into Py3k only if the performance for a single-threaded program (and for a multi-threaded but I/O-bound program) does not decrease." Unfortunately, experiments thus far have not succeeded to meet these requirements. There is some work being done by the Gilectomy project to try and meet this bar as well as some other requirements currently though [2]. But it is currently grappling with the afore-discovered performance issues that come with removing the GIL. Also at PyCon 2016, Guido himself mentions the Gilectomy project and it's potential consideration (if it works) for Python 3.6+ [3]. [1] link [2] ▶ this video [3] link
To be fair, the GIL wasn't included because it was a simple threading model (AFAIK). It was included because it was simple to implement and it was/is fast(er) (than removing it)[1][2]. If the Gilectomy [2] project succeeds, Guido has mentioned he would consider it for Python3.6+ [3]. [1] link [2] ▶ this video [3] link
The BDFL (Benevolent Dictator For Life) Guido Von Rossum himself put forth the idea that he would consider a patch removing the GIL in 2007 [1]: > "... I'd welcome a set of patches into Py3k only if the performance for a single-threaded program (and for a multi-threaded but I/O-bound program) does not decrease." Unfortunately, experiments thus far have not succeeded to meet these requirements. There is some work being done by the Gilectomy project to try and meet this bar as well as some other requirements currently though [2]. But it is currently grappling with the afore-discovered performance issues that come with removing the GIL. Also at PyCon 2016, Guido himself mentions the Gilectomy project and it's potential consideration (if it works) for Python 3.6+ [3]. So when you say Python leaders declared the GIL a "non-issue", I think you are oversimplifying the actual reality of what removing the GIL means and why leaders (like Guido) have been reluctant to invest resources pursuing. [1] link [2] ▶ this video [3] link
See Larry Hastings' talk "Removing Python's GIL: The Gilectomy" from PyCon 2016. ▶ this video As well as his earlier talk "Python's Infamous GIL". link The GIL is a simple design that provides serious benefit to Python (end user) developers. There are plenty of options for working around this for parallelism, such as the built-in module multiprocessing.