11 ms·
GraalPy – A high-performance embeddable Python 3 runtime for Java
- deleted 2y ago[deleted]
- sevensor 2y agoTook a little digging to find that it targets 3.11. Didn’t see anything about a GIL. If you’re a Python person, don’t click the quick start link unless you want to look at some xml.
- pjmlp 2y agoPython implementations naturally don't have any GIL in regards to JVM or CLR variants, there is no such thing on those platforms. YAML and JSON have both tried to replicate the XML tooling experience, only worse. Schemas, comments, parsing and schema conversions tools.
- lopuhin 2y agoI think GraalPython does have a GIL, see https://github.com/oracle/graalpython/blob/master/docs/contributor/IMPLEMENTATION_DETAILS.md#the-gil https://github.com/oracle/graalpython/blob/master/docs/contr... - and if by "there is no such thing on those platforms" you mean JVM/CLR not having a GIL, C also does not have a GIL but CPython does.
- westurner 2y ago"PEP 703 – Making the Global Interpreter Lock Optional in CPython" (2023) https://peps.python.org/pep-0703/ https://peps.python.org/pep-0703/ CPython built with --disable-gil does not have a GIL (as long as PYTHONGIL=0 and all loaded C extensions are built for --disable-gil mode) https://peps.python.org/pep-0703/#py-mod-gil-slot https://peps.python.org/pep-0703/#py-mod-gil-slot "Intent to approve PEP 703: making the GIL optional" (2023) https://news.ycombinator.com/item?id=36913328#36917709 https://news.ycombinator.com/item?id=36913328#36917709 https://news.ycombinator.com/item?id=36913328#36921625 https://news.ycombinator.com/item?id=36913328#36921625
- kaashif 2y agoThis is pretty beside the point. The point is that X not having a GIL doesn't inherently mean Python on X also doesn't have a GIL.
- westurner 2y agoCPython does not have a GIL Global Interpreter Lock GC Garbage Collection phase with --gil-disabled. GraalVM does have a GIL, like CPython without --gil-disabled. How CPython accomplished nogil in their - the original and reference - fork is described in the topical linked PEP 703.
- kaashif 2y agoYes, I know. What I'm saying is that: It's possible to have a language that doesn't have a GIL, which you implement Python in, but that Python implementation then has a GIL. The point being that you can't say things like: Jython is written in Java so it doesn't have a GIL. CPython is written in C so doesn't have a GIL. And so on. If this isn't clear, I apologize.
- westurner 2y agoOh okay. Yeah I would say that the Java GC and the ported CPython GIL are probably limits to the performance of any Python in Java implementation. But are there even nogil builds of CPython C extensions on PyPi yet anyway. Re: Ghidraal and various methods of Python in Java: https://news.ycombinator.com/item?id=36454485 https://news.ycombinator.com/item?id=36454485
- pjmlp 2y agoMy mistake, as I assumed they took the same decision as jython and IronPython. https://jython.readthedocs.io/en/latest/Concurrency/#no-global-interpreter-lock https://jython.readthedocs.io/en/latest/Concurrency/#no-glob... https://wiki.python.org/moin/IronPython https://wiki.python.org/moin/IronPython The difference between JVM, CLR and C in regards to parallel and concurrent code is that they are built for those kind of workloads, and have a memory model proper, hence not needing a GIL.
- commodoreboxer 2y agoI think they would have to here, to support native modules. Jython (and I believe IronPython, but don't quote me) does not support native CPython modules. CPython modules explicitly control the GIL, so if they are supported (as they are here), you can't really leave the GIL out without exposing potential thread safety issues.
- foobazgt 2y agoI mean, if you're trying to embed one language in another, please don't be surprised when the quickstart guide has a couple of examples containing a few lines of code written for the embedding language and its package manager(s).
- jitl 2y agoHappily, you can ignore the Maven XML and use Gradle instead, it's the next codeblock on the page, after "or": implementation("org.graalvm.polyglot:polyglot:24.1.0") implementation("org.graalvm.polyglot:python:24.1.0")
- vips7L 2y agoGradle files are less verbose than the equivalent Maven pom.xml but Gradle tends to have other issues like: complex builds that are hard to maintain, not running on the latest JVM version without some wait time, and constantly breaking because Gradle makes breaking changes every release. I'm hoping the declarative Gradle experiment [0] helps with this. Additionally if XML isn't your thing Maven is making a push for other formats in Maven 4 like HOCON [1]. [0] https://blog.gradle.org/declarative-gradle-first-eap https://blog.gradle.org/declarative-gradle-first-eap [1] https://github.com/apache/maven-hocon-extension https://github.com/apache/maven-hocon-extension
- deleted 2y ago[deleted]
- wenc 2y agoDuckDB is not currently a supported package, but Pandas and matplotlib are which is good. If DuckDB and Polars were supported and if they ran well, I suspect many data jobs could benefit.
- rsyring 2y agoWhy would they benefit? When duckdb/Polaris are being used correctly, all the work is happening in the native stack. It should already be very fast compared to the Python runtime. I recently moved a large ETL process that was mostly Python runtime processing to pyarrow/Polaris and wrote all the ETL logic in SQL. I've seen processes that used to take a week to run drop to about an hour (no exaggeration).
- wenc 2y agoThey wouldn’t benefit from performance because as you say they are already blazing fast as is. And I know what you mean — I rewrote a pure (granted old pre-2.0) pandas transformation into duckdb and compute time dropped from nearly an hour to single digit minutes. But having these in Graal would allow more types of applications to be deployed in JVM stacks. As sibling comments note, many data science models are in python but production stacks are in Java.
- rsyring 2y ago> But having them this would allow more types of applications to be deployed in JVM stack... Ah...makes sense now. I was thinking along the lines of someone switching to the JVM for better performance, but being held back by the absence of those libraries.
- tannhaeuser 2y agoI guess what makes Python interesting right now is the integration with ML toolchains, CUDA, Metal/MLX, pytorch, tensorflow, LLM encoders/decoders, etc. more than Python the language. But can GraalVM run those codes meaningfully when Python is merely used for glue code with the important bits implemented in native code?
- waldrews 2y agoLooks like all of that would run in a native sandbox environment which in turn is called from the Python running on the JVM. So, maybe it simplifies interop, but whether it's straightforward to get full performance from the native layer (especially GPU/multicore) is an open question.
- tln 2y agoYes, apparently it can https://www.graalvm.org/dev/reference-manual/python/Native-Extensions/ https://www.graalvm.org/dev/reference-manual/python/Native-E... > CPython provides a native extensions API for writing Python extensions in C/C++. GraalPy provides experimental support for this API, which allows many packages like NumPy and PyTorch to work well for many use cases. The support extends only to the API, not the binary interface (ABI), so extensions built for CPython are not binary compatible with GraalPy. Packages that use the native API must be built and installed with GraalPy, and the prebuilt wheels for CPython from pypi.org cannot be used. For best results, it is crucial that you only use the pip command that comes preinstalled in GraalPy virtualenvs to install packages. The version of pip shipped with GraalPy applies additional patches to packages upon installation to fix known compatibility issues and it is preconfigured to use an additional repository from graalvm.org where we publish a selection of prebuilt wheels for GraalPy. Please do not update pip or use alternative tools such as uv.
- theLiminator 2y agoI wonder if hpy will solve the extension problem.
- RMPR 2y ago
- theanonymousone 2y agoDoes it have to be run in a GraalVM, or any JVM implementation is fine?
- jryan49 2y agoGraal let's you compile native binaries
- ackfoobar 2y agoGraal is many things (a marketing nightmare). The guest language part is orthogonal to the native packager AFAIK.
- w10-1 2y agoYes, but I was under the impression that graal-level inter-op was limited to packages the graal toolchain could compile. Thus, while swift and graal both depend on llvm, they use different variants and there's no real way to make inter-op between swift and graal (even using the llvm it which graal is said to be able to consume). e.g., I believe this announcement represents the work to compile a python (3.11) and some proof-of-concept python packages using graal toolchain, to spur other packages to support the same. So I'd really love to be wrong, but I believe building under the graal llvm is the common factor.
- kaba0 2y agoI don’t really see how swift comes into the picture, besides SuLong being a thing (running LLVM bitcode). Native binary was meant as a compile target in the previous comment, I believe, not as an input. Graal can do both, but as a target it has no dependency on LLVM. So yeah, graalvm should be able to produce a native binary for python code (though depending on the specifics it might actually be more like a native binary interpreter running python scripts, it can’t optimize in every circumstance but I’m hazy on the details).
- Okx 2y ago> You can use GraalPy with GraalVM JDK, Oracle JDK, or OpenJDK https://www.graalvm.org/latest/reference-manual/python/ https://www.graalvm.org/latest/reference-manual/python/
- mkoubaa 2y agoHPy can eventually be used to support CPython extension modules in GraalPy
- ajdhGfa 2y agoAnd they will run how much slower or have strange bugs?
- 2OEH8eoCRo0 2y ago[flagged]
- nkzd 2y agoWhat is the use-case for GraalPy? To be honest I don't understand why would anyone want to use it.
- xyproto 2y agoData scientists trapped in bureaucracy?
- abirch 2y agoMinecraft Mods can only be written in Java and I want my kid to learn python. Jython is still 2.x and it'd be nice to let my kid write a minecraft mod in python. Not a business use case but a use case.
- smj-edison 2y agoWhen I was learning programming, my coding class used a Bukkit plugin that connected to Python. I can't remember what it was called, but that was for Minecraft 1.7.10. Not sure if you were wanting Python specifically, but KubeJS lets you use JavaScript for mods. I think there's also a clojure integration.
- abirch 2y agoThank you. My 3rd grader knows basic python so I'd prefer to stick with that or Scratch
- the_arun 2y agoI am assuming - With this, JVMs needing integration with LLMs can embed LLMs in JVM instead of making outbound API calls. If my assumption is right - wouldn't this improve performance of consumer applications?
- pjmlp 2y agoThankfully some LLMs also have Java bindings to the same native libraries used by Python.
- ajdhGfa 2y agoI'm very skeptical about production use, but the thought of Oracle taking over Python is amusing, since the Python community is already run like Oracle in a top down military manner. It can only get better!
- iLemming 2y agoWhat does that mean for Clojure?
- calrizien 2y agoIs there a way to embed Python 3 into Swift like this?
- w10-1 2y agoI haven't seen embedding using graal/vm, or inter-op using the native JVM FFI. There is (active, 2K stars) https://github.com/pvieito/PythonKit https://github.com/pvieito/PythonKit and I've heard of people being able to deploy apps with python on the app store. YMMV.
- deleted 2y ago[deleted]
- froh 2y agowhat's the advantage of this over JPype?
- mdaniel 2y agoThat it goes in the opposite direction of your cited project (run modern-ish python from within the JVM), and almost certainly has a much, much better JIT story than yours
- Rochus 2y agoIn case someone is interested, here are some benchmark results comparing GraalPy and others with JDK8 using the Are-we-fast-yet benchmark suite: https://stefan-marr.de/downloads/tmp/awfy-bun.html https://stefan-marr.de/downloads/tmp/awfy-bun.html And here is a table representation of all benchmarks and the geomean and median overall results: http://software.rochus-keller.ch/awfy-bun-summary.ods http://software.rochus-keller.ch/awfy-bun-summary.ods The implementation of the same benchmark suite runs around factor 2.4 (geomean) faster on JDK8 than on GraalPython EE 22.3 Hotspot, or 41 times faster than CPython 3.11. GraalPython is thus about 17 times faster than CPython, and about two times faster than PyPy. The Graal Enterprise Edition (EE) seem to be factor 1.31 faster than the Community Edition (CE).
- masklinn 2y agoYour mileage may very much vary, much like pypy this is very inconsistent and highly dependent on your workload (as well as your dependencies). My limited experience was that on re-heavy workload pypy is several times slower than cpython (~3x compared to 3.10) and graal is even worse (~6x compared to 3.11).
- mike_hearn 2y agoWhich version was that with? GraalVM can JIT compile regular expressions these days, with the same compiler as everything else. They implemented TRegex on top of Truffle so regex can be inlined and optimized like regular code. Performance does indeed depend on workload. There's a page that compares GraalPy vs CPython and Jython on the Python Performance Suite which aims to be "real world": https://www.graalvm.org/latest/reference-manual/python/Performance/ https://www.graalvm.org/latest/reference-manual/python/Perfo... There the speedup is smaller, but this is partly because a lot of real world Python workloads these days spend all their time inside C or the GPU. Having a better implementation is still a good idea though, because it means more stuff can be done by researchers who don't know C++ well or at all. The point at which you're forced to get dedicated hackers involved to optimize gets pushed backwards if you can rely on a good JIT.
- 2y ago
- upghost 2y agoFWIW we've had full Java/Python integration in Clojure for awhile now, courtesy of Chris Neurnberger and libpython-clj: https://github.com/clj-python/libpython-clj https://github.com/clj-python/libpython-clj If you're into that sort of thing. Self-interest disclosure: I'm a major contributor and heavy user.
- waldrews 2y agoWhat's the GIL/threading story there?
- upghost 2y agoI'm assuming you mean "how well does JVM concurrency play with Python concurrency"? Python concurrency works perfectly well on its own, Java/Clojure concurrency works very well on its own, trying to pass multithreaded information across the JVM boundary to Python while bypassing the GIL will result in a segfault (Edit: but there are "with-gil" wrappers you can use to prevent that, at a slight performance hit). In practice this tends not to be much of a problem as you setup a parallel workload on one side of the boundary or the other and pass information with a threadsafe queue. We do plenty of heavy parallel computations, data science, AI, fintech, etc. There are certainly some leaky abstractions and there is a general expectation that you understand the quirks of Python and Clojure pretty well, so it's not for everyone. Knowing something about Java would probably help too but I've been using libpython-clj in production since 2017 years and I barely know anything about Java (compared to Python/Clojure).
- malux85 2y agoThis is pretty interesting, what's the benefit over using python so directly with java? I mean, is the overhead of having these as seperate services / processes too much? I'm not trying to provoke I'm genuinely curious about the use case. Also, what's the dev workflow like? When I'm coding python I basically live inside the debugger (a.k.a the carmark method), do you use an IDE that understands both java and python? Whats the debugging experience like? Can you set a breakpoint and then evaluate python code and expressions inside the debugger like you can if it was just solely a python project using VSCode and the python debugger?
- Abismith 2y ago[dead]
- Abismith 2y ago[dead]
- abernard1 2y agoAn honorific. So much of this dynamic language performance improvement on the Graal JVM was proven out by Chris Seaton. May he rest in peace.
- wetpaws 2y ago[dead]
- nprateem 2y agoAm Internet point for the first working demo with django + postgres.
- fniephaus 2y agoOP here. More details about this particular release are in the blog post at https://medium.com/graalvm/whats-new-in-graal-languages-24-1-b2452c9debae https://medium.com/graalvm/whats-new-in-graal-languages-24-1... Happy to answer any additional questions!
- nurettin 2y agoHi, what's the deployment process like? Is there a program similar to warbler (for jruby) that builds a jar for a python program? EDIT: I tried the native binary command here on a simple hello world script. It downloaded some stuff in the background, built the entire python and java and embedded it into a 350 MB ELF binary on linux after 15 minutes of using 24 GB RAM and 100% CPU. But I'd much prefer a smaller jar file which I can distribute cross-platform. https://www.graalvm.org/uploads/quick-references/GraalPy_v1/quick-reference-graalpy-v1(eu_a4).pdf https://www.graalvm.org/uploads/quick-references/GraalPy_v1/...
- fniephaus 2y agoThanks for the question, nurettin. Although GraalPy can create standalone applications [1], you don't have to turn your hello world script into a self-contained binary. You can, of course, create a JAR that depends on GraalPy, or a fat JAR that contains it, and deploy it just like any other Java application. We are still updating our docs to mention more details on this and publish some guides, apologies for the delay. [1] https://www.graalvm.org/latest/reference-manual/python/standalone-applications/ https://www.graalvm.org/latest/reference-manual/python/stand...
- jsmeaton 2y agoTried to use graalvm (interpreter) to run a fairly large project at my $dayjob$ and ran into a few issues right away. - Maturin doesn't support the graal interpreter, so no Py03 packages - uv doesn't seem to run, as `fork` and `execve` are missing from the os package? - Graal seems to have a huge number of patches to popular libraries so that they'll run, most seem to be of the form that patch c files to add additional IFDEFs I don't think Graal is going to be a viable target for large projects with a huge set of dependencies unfortunately, as the risk of not being able to upgrade to different versions or add newer dependencies is going to be too high. It's impressive what it does seem to support though, and probably worth looking at if you have a smaller scale project.
- nomercy400 2y agoTo be fair, this also happened when Graal was released for Java. Give it another go in 3-6 months, the Graal team will have improved interoperability massively. It is a chicken (interpreter) and egg (dependencies) problem. You cannot fix the dependency problems without the interpreter. Neither can you release an interpreter with full dependency support.
- sitkack 2y agoFor projects using GraalPy, I'd wager that most would vendor all their dependencies at the start of the project and upgrade along the way. I have shipped a couple products with Jython, and very little 3rd party code was used and almost none of the standard library, it was all driving Java from the same project. So it does have to do with scale but in the opposite direction. Big long projects will want to adopt something like GraalPy because of how long the project will take.
- jsmeaton 2y agoWhat I was hoping to be able to do was run our existing cpython project on graal to try and benefit from whatever speedups the jvm (or, if possible, compiling to a native module) would provide, rather than build with the jvm specifically in mind from the get go.
- cout 2y agoCould this directly invoke Java (or Scala) functions without using a bridge? If so this would be great for programs that use spark -- UDFs would become performant enough to consider using on medium-to-large dataframes.
- pantulis 2y agoGraalVM is fascinating. Honest question: what are Oracle's plan for it? How does it serve them?
- mk89 2y agoThere is already an EE for it, so I guess they provide basic functionalities for free, and if you need additional features you have to pay?
- mike_hearn 2y agoEE is mostly free to use actually (check the licensing FAQ for exactly when). Graal features get integrated into Oracle products and make them better.