LWN: Comments on "Grok the GIL (opensource.com)" https://lwn.net/Articles/720549/ This is a special feed containing comments posted to the individual LWN article titled "Grok the GIL (opensource.com)". en-us Sun, 19 Oct 2025 12:06:57 +0000 Sun, 19 Oct 2025 12:06:57 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Grok the GIL (opensource.com) https://lwn.net/Articles/721391/ https://lwn.net/Articles/721391/ flussence <div class="FormattedComment"> I'd consider Perl 6 mainstream, all mainstream distros are making an effort to package it, it's regularly shipping Windows/MacOS/Docker installers, is supported on various "exec arbitrary code on our server" sites, and even GitHub's broken and subpar syntax/doc rendering toolchain now partially acknowledges it exists.<br> <p> But to play the numbers game a bit, I'd like to point out that PHP provides a genuine shoe-facing hand cannon: <a href="http://php.net/pthreads">http://php.net/pthreads</a><br> </div> Sat, 29 Apr 2017 19:08:31 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/721303/ https://lwn.net/Articles/721303/ mstone_ <div class="FormattedComment"> And pdf.js tends to print like crap.<br> </div> Fri, 28 Apr 2017 15:30:07 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720906/ https://lwn.net/Articles/720906/ pboddie <div class="FormattedComment"> Except that Hipster 2.0 sites - those that use JavaScript for everything, which is where this ends up - don't tend to gracefully degrade, instead leaving a jumble of elements or even a blank page since the text and graphics aren't able to glide in smoothly from off the sides of the screen without scripts activated (or whatever special effect it is that is inevitably needed to spice up the ten to twenty words of actual content). On my rather old machine, such animations are wasted anyway: by the time the browser has woken up to the task of animating, the end of the animation timeline is upon it, and it might as well just put things in their final positions.<br> <p> Also, while I'm impressed with things like PDF.js, I find myself using a native viewer like Okular for documents of any size, purely because the performance difference is significant. So, JavaScript-based equivalent solutions certainly have their limitations.<br> </div> Tue, 25 Apr 2017 17:24:42 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720842/ https://lwn.net/Articles/720842/ niner <div class="FormattedComment"> Perl 5 threads have never been more than a base for fork() emulation on Windows. Ironically there's a drop in replacement called "forks", so instead of "use threads" you write "use forks" and get even better performance.<br> </div> Tue, 25 Apr 2017 11:50:04 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720843/ https://lwn.net/Articles/720843/ rahulsundaram <div class="FormattedComment"> Is Perl 6 considered a mainstream scripting language?<br> </div> Tue, 25 Apr 2017 11:49:44 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720841/ https://lwn.net/Articles/720841/ niner <div class="FormattedComment"> Perl 6 does support proper multithreading.<br> </div> Tue, 25 Apr 2017 11:48:47 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720838/ https://lwn.net/Articles/720838/ karkhaz <div class="FormattedComment"> Slightly orthogonal issue: it seems ridiculous to have client-side computation for something that will compute exactly the same result on every client's machine. Why not do the syntax highlighting once on the server and serve the result to everybody, saving their battery life and cutting an iota from the page latency?<br> </div> Tue, 25 Apr 2017 11:41:27 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720835/ https://lwn.net/Articles/720835/ jond <div class="FormattedComment"> One could argue that losing syntax highlighting is still consistent with using Javascript in a "gracefully degrade" fashion.<br> </div> Tue, 25 Apr 2017 10:47:11 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720826/ https://lwn.net/Articles/720826/ Sesse <div class="FormattedComment"> Perl? The Perl 5 threads are deprecated, though.<br> </div> Tue, 25 Apr 2017 07:06:47 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720821/ https://lwn.net/Articles/720821/ Cyberax <div class="FormattedComment"> Lua is not really free-threaded, you can use it in multithreaded environment as long as you're extra-careful with data sharing.<br> <p> So far I don't know _any_ mainstream scripting languages that have proper multithreading. <br> </div> Tue, 25 Apr 2017 05:43:49 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720820/ https://lwn.net/Articles/720820/ pabs <div class="FormattedComment"> Please don't, you will alienate people who do not allow JavaScript to run.<br> </div> Tue, 25 Apr 2017 03:55:21 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720815/ https://lwn.net/Articles/720815/ sciurus <div class="FormattedComment"> If you're building a web application, consider doing syntax highlighting client-side using a library like <a href="http://prismjs.com/">http://prismjs.com/</a><br> </div> Tue, 25 Apr 2017 01:33:46 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720712/ https://lwn.net/Articles/720712/ njs <div class="FormattedComment"> The main reason PyPy's not widely used is that people don't use Python for just the language, but also the ecosystem. And it turns out that ecosystem has a bunch of important libraries that are written against the CPython C API, which more-or-less exposes all of CPython's internal implementation details. This makes it extremely difficult for alternative implementations to get traction. (There's even tons of code out that there that implicitly assumes a refcounting gc – the Pyston folks actually started with a fancier GC and then switched back to refcounting to improve CPython compatibility.) None of this is how you would ideally want anything to work, but when it's ideals versus the 100,000 packages on PyPI, the 100,000 packages tend to win.<br> <p> It doesn't help that Python's semantics are much richer than other dynamic languages like JS and Lua (and I suspect lisp too) in a way that makes effective JITting much harder – e.g. a basic operation like attribute lookup involves like 10 different special cases you have to check. This is what motivates PyPy's weird architecture – they need a JIT engine that can introspect "basic operations" like this and automatically generate context specific optimized variants, so they implement these operations in a high-level language ("RPython") that their JIT engine can see through.<br> <p> The good news is that the PyPy devs have been doing a truly heroic job over the last ~year on polishing up their fake CPython C API layer to the point where it's starting to be able to handle gnarly old libraries like numpy, lxml, etc. So hopefully this last major roadblock will be removed soon.<br> <p> </div> Sun, 23 Apr 2017 12:26:12 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720711/ https://lwn.net/Articles/720711/ njs <div class="FormattedComment"> The GIL in Python 3 (starting in 3.2) is significantly different from the one in Python 2 that this article mostly focuses on...<br> <p> Probably the best extant documentation on how they work and the differences between them is: www.dabeaz.com/python/UnderstandingGIL.pdf<br> <p> PyPy's GIL is different again and AFAICT immune to all the pathological cases described in that talk... it's pretty interesting stuff.<br> </div> Sun, 23 Apr 2017 12:14:40 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720708/ https://lwn.net/Articles/720708/ Sesse <div class="FormattedComment"> To be honest, I believe even LuaJIT without the JIT would be faster than most languages in this class. JIT versus interpreter is only one part of the equation; just as important is things like value representation. Lua has a head start there in terms of being a simple and small language, which helps. That, and the LuaJIT guy is brilliant.<br> </div> Sun, 23 Apr 2017 11:00:21 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720707/ https://lwn.net/Articles/720707/ joib <div class="FormattedComment"> The sort-of sad thing is that python (or to be specific, cpython which is the implementation ~everybody uses) is still a simplistic bytecode interpreter which uses reference counting. I mean, come on, the 1970's called. <br> <p> Meanwhile, say, Lisp, a similarly dynamic language, has had sophisticated native code compilers and generational GC for decades. Whereas in the python world efforts like unladen swallow (sp?) fail or are not widely used (pypy). What gives?<br> <p> Not to pick on python specifically, ruby, perl, R, octave etc. are all equally bad. LuaJIT and modern JavaScript runtimes are the happy exceptions, though. Perhaps one shouldn't draw too much conclusions from javascript, considering the $$$ spent there, but then again, LuaJIT is basically a one-man show.<br> </div> Sun, 23 Apr 2017 10:39:47 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720705/ https://lwn.net/Articles/720705/ khim <div class="FormattedComment"> Yes, TensorFlow does not use Python for much... and usually GIL is not a problem... yet in certain use cases almost half of wall-clock time in spent in Python. I believe dvyukov have some numbers.<br> </div> Sat, 22 Apr 2017 18:45:13 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720662/ https://lwn.net/Articles/720662/ niner <div class="FormattedComment"> So which native library do you recommend as replacement for <a href="http://pygments.org/?">http://pygments.org/?</a><br> </div> Fri, 21 Apr 2017 16:40:36 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720658/ https://lwn.net/Articles/720658/ Sesse <div class="FormattedComment"> As someone who has had TensorFlow optimization as a day job (in the Google Brain team)… sorry, it's a bad example. :-) But it doesn't really use Python for much except just setting up the graph and then pressing play.<br> </div> Fri, 21 Apr 2017 15:51:38 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720657/ https://lwn.net/Articles/720657/ khim Yup. Think <a href="https://www.tensorflow.org/">TensorFlow</a>. Highly-optimized C++ code with threading pools and everything, 99% of CPU time is spent there. 1% is spent in linear (because if GIL) python “driver”. Now think about “monster desktop” with two <a href="https://ark.intel.com/products/93790/Intel-Xeon-Processor-E7-8890-v4-60M-Cache-2_20-GHz">Monster Xeons</a>. 96 threads, add <a href="https://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl's law</a> and... vila: almost <b>half</b> of wall-clock time is spent in python! Still think GIL is “not a big deal if core of your toolboox is in C++”? Fri, 21 Apr 2017 15:46:56 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720592/ https://lwn.net/Articles/720592/ kigurai <div class="FormattedComment"> I agree that most CPU intensive stuff is already done in C-libraries, but I am not so sure this makes the point of removing the GIL moot.<br> Sometimes you have a library function that does the computations in C (fast) but you need to run it on a shitload of data, and the library itself is not built for that.<br> Today you solve that by e.g. multiprocessing.Pool() but if the data you are operating on is large, or not picklable, then you either can't, or at least have to write quite complicated boilerplate code to share the data somehow.<br> Thus I would really love to instead be able to use a pool of threads that can all freely share the data I have already loaded, which is of course impossible as long as the GIL remains.<br> </div> Fri, 21 Apr 2017 11:20:13 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720591/ https://lwn.net/Articles/720591/ excors <div class="FormattedComment"> Or if they do follow that pattern, and they switch to libXYZ which is 100x faster, then the not-XYZ work which used to take 10% of the execution time is now taking ~92%. Now they're back in the same pattern, and (if they're operating at a large enough scale that hosting costs outweigh development costs) they really need to optimise all that non-XYZ code.<br> <p> That process will repeat until there are no identifiable bottlenecks, they've just got hundreds of thousands of lines of Python code that are uniformly slow, and then they'll want to make Python faster. (It's basically Amdahl's law - once you speed up everything you can, performance is likely dominated by the parts you couldn't speed up.)<br> </div> Fri, 21 Apr 2017 11:04:26 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720589/ https://lwn.net/Articles/720589/ Sesse <div class="FormattedComment"> Well, for one, the HTML templating systems tend to be pure-Python, and they take a non-zero amount of time. And if you're using a web framework, all sorts of routing logic… It all adds up. Talking to the database is usually only a small part.<br> <p> This isn't unique to Python, by the way. Perl, Python, Ruby, Lua… most applications I've seen _don't_ have this “90% of time is spend in doing XYZ, so just use libXYZ from C” pattern.<br> </div> Fri, 21 Apr 2017 09:58:35 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720588/ https://lwn.net/Articles/720588/ quietbritishjim <div class="FormattedComment"> I would have thought that "Basically anything related to the web" is going to spend most of its time interacting with a database, which of course is I/O. What's more, database interactions run fastest (even with one thread) when you put as much logic as possible into prepared statements, just as numpy runs fastest when you heavily vectorise your operations. Maybe you could elaborate on what you think of as a web application? I'm genuinely curious.<br> <p> More broadly, if you have a Python application in any domain that's using loads of CPU in the interpreter then I think you've used the wrong language, because native code will be orders of magnitude faster. Removing the GIL is not going to change that. An obvious counter argument is that CPUs are cheap. Yes, but are they so cheap that you can afford to buy 100 times as many web servers?<br> <p> It's OK that Python is hopelessly slow because it's intended as a glue language that just coordinates fast code (in-process C extensions or out-of-process via I/O). This works really well because most code is actually the same in different applications, so with this strategy the shared code gets written once in a native language (in numpy or Postgres or whatever) and the tiny amount of application-specific code gets written in Python. As I see it, the GIL doesn't have much effect on this.<br> </div> Fri, 21 Apr 2017 09:01:43 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720587/ https://lwn.net/Articles/720587/ Sesse <div class="FormattedComment"> <font class="QuotedText">&gt; This is what CPU heavy Python apps usually spend most of their time in anyway</font><br> <p> Not necessarily. There are tons of cases (basically anything related to web) where you spend your time in the Python interpreter, not in C extensions.<br> </div> Fri, 21 Apr 2017 08:34:51 +0000 Grok the GIL (opensource.com) https://lwn.net/Articles/720581/ https://lwn.net/Articles/720581/ quietbritishjim <div class="FormattedComment"> "... while it sleeps, does I/O, or some other GIL-dropping operation ..." While technically true, this hides the fact that "some other GIL-dropping operation" can be pure CPU computation in a C extension, e.g. compressing a buffer in zlib or multiplying large matrices in numpy. This is what CPU heavy Python apps usually spend most of their time in anyway, so it makes the GIL a much less big deal than it seems at first.<br> </div> Fri, 21 Apr 2017 06:10:20 +0000