Let's say CPython can gain a JIT or get rid of the GIL, but not both. Which would you want to have more?
JIT
51%
No GIL
49%
Poll ended at .

@brettcannon

No GIL. It would mean being able to use (pure) Python for parallellizable tasks without having to launch multiple processes of it and set up IPC for synchronizing the task execution.

If Python were too slow for me (and a JIT would help), I could try to solve that by using a more powerful server or adding more servers.

@mattwelke What if you had multiple subinterpreters in the same process which each had their own independent GIL?
@brettcannon @mattwelke I guess that depends. Two things that I'd love to see for a python webserver utilizing no-gil: use a threadpool and a connection pool directly in the app, allow stuff like Prometheus the work efficiently (currently due to multi process deployments they have write values to files and reread them). I don't think gilfree subinterpreters would solve that immediately since communication/coordination would be quite limited between them. Also no exec and threads in them iirc?
@apollo13 @mattwelke The interpreters are the threads (think Erlang-style CSP).
@brettcannon And removing the GIL does not have disadvantages (except that someone must do (did) the implementation)? I doubt that, as I don’t think we all really understand the downside of non-GIL. And therefore, I think this survey is pointless.

@bronger I think saying "this survey is pointless" is a bit presumptuous without knowing my motivation behind the survey and why I structured it this way.

You not knowing the details is on purpose for what I'm interested in knowing about people's perception of both topics.

@brettcannon I know that the result cannot be used if the prerequisites/context of the measurement are unclear.
@bronger
We do know the downsides of no-GIL: Assumptions based into existing pure Python code and C extension modules written over the past 30 years break.
@brettcannon

@gpshead @brettcannon How many modules are affected? Do modules have to be maintained in two variants? How difficult is the migration? Will the GIL be off by build settings or interpreter arguments?

Think of how difficult is was to estimate the costs of Python 3000! Every survey has inaccuracies but this is too much.

If you just want to know whether vertical or horizontal scaling is more important, ask that instead.

@brettcannon JIT will give more immediate results at least in web, because we already have so much infrastructure in place to create multiple processes instead of threads. Removing the GIL will open Python up to doing a lot more with threads, but so much of our existing web stuff is already built for multi-process. The downside by experience is a Python app with many processes uses up so much RAM.
@brettcannon Since we know that state-of-the-art JITs are multithreaded β€” see JVM and CLR β€” that seems like an unfortunate trade-off that can only have negative consequences for Python.
@apparebit That's a technical detail. Whether or not the JIT components of an interpreter are multi-threaded doesn't have to have anything to do with the GIL (i.e. CPython could release the GIL why JITing code just like it releases the GIL today when reading files).
@brettcannon Let me try again: If you build a JIT, you’ll have to tailor the garbage collector for it anyways. The distance from that to thread-safe JIT isn’t that bad. Or to put this differently, a JVM or CLR implementation of Python wouldn’t need a GIL. Using one anyways, like Jython, destroys much of the value of targeting such a runtime. If you are serious about JIT for Python, I’d recommend targeting WASM period. It gives you web for free as well.
@apparebit Why do you think a JIT requires changing the garbage collector? https://www.trypyjion.com/ showed we can keep reference counting and still apply a JIT for some performance wins.
Pyjion - A Python JIT Compiler

@brettcannon Because determining liveness (for tracing GC) and updating references (for copying GC) isn't safe at arbitrary points of program execution. I know CPython uses reference counting but also remember there being a fallback (for the invariable cycles). The LLVM documentation gives a good overview: https://llvm.org/docs/Statepoints.html
Garbage Collection Safepoints in LLVM β€” LLVM 17.0.0git documentation

@brettcannon I voted for JIT.

I believe it would bring the clearer and most immediate benefits for all python workloads already out there.

@brettcannon in my work, the GIL has not once been a problem for me; it may be an issue for some, but it's a problem that we've worked around quite effectively for a while now with processes. I voted JIT.
@itsthejoker @brettcannon Quite the opposite for me πŸ˜‚ Voted accordingly
@foosel @brettcannon haha that makes perfect sense to me. We use python for different things 🀷
@foosel @itsthejoker Is it specifically the lack of free threading, or just more parallel execution options? For instance, if you could have multiple subinterpreters in the same process which each had their own thread, would that have helped?
@brettcannon @itsthejoker It is specifically the lack of free threading. I'd need a ton of IPC to be able to spread things across multiple processes, and that is not going to scale.
@foosel @itsthejoker Based on how you phrased that it isn't free threading but lack of IPC. https://peps.python.org/pep-0554/ mght get you that w/o dropping the GIL entirely.
PEP 554 – Multiple Interpreters in the Stdlib | peps.python.org

Python Enhancement Proposals (PEPs)

@brettcannon @itsthejoker maybe. but I run a project that has a plugin system and frankly getting IPC wrapped transparently so (often inexperienced) plugin authors have it as easy as possible sounds like the opposite of a good time 😬

Plus I'm currently still stuck on a minimum supported python version of 3.7 due to this being a thing that users self-install in their own environment.

Admittedly that also means years before -GIL or +JIT would help me anyhow πŸ˜…

@brettcannon ho ho! controversy. Have people also put "how many years have you been using Python?" and watch the old timers all go for JIT

@brettcannon a JIT would make life immediately better. no GIL would be...how would that even work, would modules have to declare "from __future__ import nogil" to guarantee that they have used threading.Lock() every time they pop from a dictionary? common people VOTE FOR JIT

#nocampaigningnearthevotingarea

@zzzeek @brettcannon strong agree, coming from the view that the GIL was a good idea in the first place. It was a tradeoff that acknowledged that most software isn’t massively parallel. Even with decades of progress, single-threaded performance continues to be king. A truly great JIT would be transformative. Getting rid of the GIL would be great, but would require significant code and architectural changes to take advantage. Gimme dat JIT!
@jonathan @brettcannon WEIGHT THE POLL FOR VETERANS
@zzzeek @brettcannon raise your hand if your ~/.vimrc is older than most of the voters! :D
@zzzeek @jonathan It's actually already skewed towards the "well-aged" Python developers since they are giving the most nuanced replies ATM. πŸ™‚
@zzzeek @brettcannon the JIT could also know when it’s safe to drop the GIL for longer runs of code…
@brettcannon I run network services at (medium) scale, if the gil was gone I'd still be running asyncio. A good jit would do wonders for latency and cost, and allow more use cases (could do more data processing within a req resp cycle). nogil would unlock a little efficiency (run several asyncio threads while sharing the interpreter and some resources like connection pools, I guess?) but nothing too revolutionary, at the cost of significant complexity

@brettcannon Not quite sure where I lean on this.

On the one hand - no GIL would be great. It really hurts to run single-core on multi-core machines.
On the other hand - I'm pretty sure we'll have to rewrite most existing libraries to be properly thread-safe, and I don't think anyone wants that. I mean - how do you even go about it? Add "no GIL" as a specifier for packages?

JIT is tricky as well. Can `inspect` keep working as it is? Will we have to give things up? How do we manage that?

@tmr232 https://peps.python.org/pep-0703/ for the no-GIL details, but yes, packages would need "GIL" and "no GIL" wheels.

As for the JIT, why do you think 'inspect' would stop working when the source code had to be there to JIT to begin with?

PEP 703 – Making the Global Interpreter Lock Optional in CPython | peps.python.org

CPython’s global interpreter lock (β€œGIL”) prevents multiple threads from executing Python code at the same time. The GIL is an obstacle to using multi-core CPUs from Python efficiently. This PEP proposes adding a build configuration (--disable-gil) to...

Python Enhancement Proposals (PEPs)
@brettcannon Python already compromises performance to ensure all stack frames are present and look the way they should.
If we add JIT, we'll still need to ensure all variables & stack frames are properly populated. A bit like a debug build.
I assume that this will result in significant performance loss compared to a version without those guarantees.
@tmr232 I trust the Faster CPython team to know what they are doing if/when they tackle a JIT (I know they are contemplating it).
@brettcannon My believe is that both are possible and I think the possibilities of no gil are greater in the long run.
@brettcannon Thinking if #NoGIL is sorted first, making JIT happen later is probably much easier than the other order.
@tsvenson Maybe since I know the JIT will be harder to do w/o a GIL. But because of that I'm not sure if you would get both.

@brettcannon But by trying we will learn a lot of things that will benefit Python and the community in other ways? Such as for the initiative to make Python x times faster.

So, there is much to gain just by trying - which is also the only way to find out if it can be done 🀘

@brettcannon I haven’t followed either conversation closely. Are there technical reasons why one would prevent the other, or is this more about dev resources? Or just a an exercise to reveal prioritization?
@jacob
Resources and community priority curiosity.
@brettcannon
@gpshead @jacob What Greg said, although I believe some initial JIT thinking makes having a GIL easier (plus all the recent perf work in 3.11 obviously assumed a GIL).
@brettcannon @gpshead @jacob As with lazy loading, the uncertainty of existing code supporting or being compatible with these new features is a serious concern. But if we don't offer a way to try out such features, how are we going to get past this obstacle? What incentive would projects have to do something about it?
@ivoflipse @gpshead @jacob Who is the "we" in your question? _You_ or anybody else can make the offer of an example implementation. But unless someone sponsors a grant for the PSF to make this all work then it's up to those doing the work what we get to try.
@brettcannon @gpshead @jacob we as a community, since you also maintainers on board to make or accept the changes, folks to test packages to find any problems, core devs to deal with the consequences for the stdlib. When you say fund this work, are we talking a dedicated 4Developer in Residence or what kind of price tag do you have in mind?
@ivoflipse @gpshead @jacob When I say "fund" I mean just make it happen somehow. It can be by a company paying their own employee(s) to build something, it could be by funding a grant to the PSF for this work. Or it could be by funding another developer-in-residence. I personally don't care the mechanism, just that people realize that asking the core devs to do it voluntarily is a big ask.
@brettcannon @gpshead @jacob perhaps it would be good to mention this on Discuss? I feel like your point of view doesn't seem well represented there right now. This seems like the first PEP (that I know of) that would be conditional on a certain level of funding, so it would be good to hear everyone's perspective. Perhaps the same applies to the packaging discussions, which efforts could benefit from funding
@ivoflipse @gpshead @jacob Technically every PEP is conditional on "funding" from the perspective of the person proposing it is expected to make it happen.
@brettcannon Doesn't pypy already have JIT and it only gives like 10% performance boost? Where as no GIL would make my code 3200% faster and mean I never have to deal with the nightmare of cross platform IPC ever again.
@ali1234 @brettcannon That can be improved alot, the newer one looks to be around 30% faster ( https://shopify.engineering/ruby-yjit-is-production-ready ). But I'm also team no gil since most the hot loops in my code are already running in some other more efficient system.
Ruby 3.2’s YJIT is Production-Ready

YJIT, a just-in-time (JIT) implementation on top of CRuby built at Shopify, is now production-ready and delivering major improvements to performance and speed. Maxime shares the updates that have been made in this newest version of YJIT, and future plans for further optimization.

Shopify
@bluegreenzeros @ali1234 Actually you don't need to have no GIL to get parallelism w/o IPC as there's the potential for https://peps.python.org/pep-0554/
PEP 554 – Multiple Interpreters in the Stdlib | peps.python.org

Python Enhancement Proposals (PEPs)

@brettcannon @bluegreenzeros

I assume you meant 684. But if you have multiple interpreters, how do they share objects without a (shared) GIL?

@ali1234 @bluegreenzeros Nope, I meant PEP 554. PEP 684 is the technical underpinnings for per-interpreter GILs, but PEP 554 proposes a public API at the Python level to leverage subinterpreters (and thus answers your question πŸ˜‰).

@brettcannon

Please refer to my test case here: https://bpa.st/47SDC

Multiple interpreters doesn't solve my problem unless there is also a no-GIL communication channel between them.

View paste 47SDC

@ali1234 @brettcannon

Usage is explained in pep554, TLDR still has GIL limitations, but wants to do the following:
* increase exposure of the existing feature, which helps improve
the code health of the entire CPython runtime
* expose the (mostly) isolated execution of interpreters
* preparation for per-interpreter GIL
* encourage experimentation

Overall, this could be interesting and I can imagine some libraries written on top of it, but doesnt solve the problem significantly enough for me

@brettcannon jit is my vote. I believe it'd get greater flexibility in experimentation, jit implementation, and production use. We could see different jits for different processing use cases, written in C++, rust, java, etc., enabled in some pieces of the software and not others, etc.

If there's a good all-around jit then it could get used as a standard in sub-interpreters, and you'd still be able to use a java-implemented jit for jython-compatible code, perhaps.

@brettcannon This is evil i want both 😭

@bluegreenzeros If you or your company would like to fund such an effort to have both, I am sure an arrangement can be made with the PSF to fund such an endeavour πŸ˜‰

https://www.python.org/psf-landing/

Welcome to Python.org

The official home of the Python Programming Language

Python.org

@brettcannon i vote #NoGIL. I do machine learning research, often prototyping code on my local computer (with a quite competent multicore CPU), and i think threads could give me quite some improvements there. Not bringing out the big guns like dask every time might improve latency in development iterations, for example. On the other hand, i think I am badly informed about the implications of a #JIT compiler.

Would love an episode of @pythonbytes discussing the topic.