9 ms·
Native Clojure with GraalVM
- tosh 8y agotalk: https://www.youtube.com/watch?v=kjZP_wBQJ2U https://www.youtube.com/watch?v=kjZP_wBQJ2U tl;dr: surprisingly Clojure code benefits a lot from aot compilation
- wink 8y agoAfter hearing about GraalVM first time at a PolyConf talk last year I sat down with one of the GraalVM folks and we (well, I was just providing info) did a few performance measurements if this could speed up the startup time (especially for leiningen tasks) - the preliminary results were pretty cool. So if you're using Clojure and Leiningen and are annoyed by the long startup times... there's potential :)
- Rovanion 8y agoDid Leiningen compile through Graal without modification?
- wink 8y agoNo, at least not back then. Otherwise we might have an official branch or PR already. I didn't really follow up on this, this was just a quick hack session to see if we could get something like "lein version" or "lein deps" or something to run and compare the speed. One main problem I also see is the distribution. Currently leiningen only needs "some sort of java executable" and then the rest is pulled in. So would you have to have GraalVM installed or could this also be bootstrapped.
- zcam 8y agoIt's not all unicorns though. Performance can vary quite a lot from task to task, also compile times suffer a lot and you lose some dynamic features. So from what I understand it might be useful for clojure cli apps, but at this point I am not sure it brings a lot, but this is early days. The cool part is the polyglot capabilities imho. Then there's the elephant in the room: the licensing and potential changes in the long run. For clojure if you want decent cli/startup experience there's always cljs, lumo or you can go with something like fennel-lang, a clojure looking lisp that "transpiles" to lua(jit), so 0 overhead compared to lua and super fast startup. https://fennel-lang.org/ https://fennel-lang.org/
- wink 8y agoYeah, but I don't see anyone rewriting leiningen in cljs anytime soon. For general CLI tools, yes, I'd also look into cljs at this time.
- zcam 8y agoYou'd be surprised, there are people in the community with some clever ideas to do that with a (fast)client/server model and change diffing (incremental builds), but it's super early days. With tools.deps and the need of some companies for more advanced build setup a lot of people are actually thinking about these issues.
- wink 8y agoI'm not denying that someone, somewhere is working on something. But I'd be surprised indeed, I'm not watching the whole clojure space closely, I can only say that no one hit the #leiningen irc channel or posted something on the bugtracker/proposed a PR yet. And the client/server model.. sure, nailgun and grenchman were a bit clunky, but none of these efforts have gained widespread adoption, afaik. Most people don't just go out of their way to tweak their build tool.
- zcam 8y ago> And the client/server model.. sure, nailgun and grenchman were a bit clunky, but none of these efforts have gained widespread adoption, afaik. Most people don't just go out of their way to tweak their build tool. I was not thinking about these two, nor was I thinking about a patch for boot/lein. That said the slow startup issue is only really valid for cli apps (and maybe CI), if your dev workflow relies on re-starting your repl all the time, it's a broken workflow.
- jjwiseman 8y agoThere is a group of people that love to say this ("If you're not using a repl or restarting your repl all the time, you're doing it wrong"), but I've been using Lisp for more than 20 years and I don't agree. A repl is nice, and I use one often, but it does have tradeoffs. One is persistent state--It can be quite easy to get your repl into a state where your code works, but if you run the app from scratch it doesn't because definitions are out of sync (e.g. you renamed a function, but forgot to change the name at a call site, so you end up calling an old version of the function.) Developing in a repl is nice, but it's not the only allowed or legitimate or even good way to do development in Lisp or other dynamic, interactive languages. Clojure has an issue with slow startup (another tradeoff made for good reasons that don't fit everyone's situation)--denigrating other people's development approaches doesn't solve that, it comes off as defensive.
- zebraman 8y agoFor command-line applications, it opens up an interesting space. There was a post on HN a while ago: https://www.astrecipes.net/blog/2018/07/20/cmd-line-apps-with-clojure-and-graalvm/ https://www.astrecipes.net/blog/2018/07/20/cmd-line-apps-wit... though the system requirements for compilation are at the moment very onerous.
- wink 8y agoApparently I missed this one, thanks! > So you have no excuses not to build your CLI tools in Clojure now. Well I do disagree with this part, see other sibling comments (not by me). I'm not even sure GraalVM is really production-ready, notwithstanding the potential licensing and long-term issues. I do agree it's at least worth trying.
- zebraman 8y agoWe are starting to do that, and for very simple operations, it works (like scripts for maintenance that we deploy remotely, and run as cron jobs). So far no big surprises, but we were very careful. The big minefield is that you do not really know which libraries will go boom and where, as any place could make use of class loading.
- repolfx 8y agoWhat licensing issues do you have in mind. Graal and SubstrateVM are all GPL-with-classpath-exception licensed, same as Java itself. It's an open source license.
- mping 8y agoThere's some libs that don't quite work with GraalVM yet, due to some unsupported features. I'm guessing these issues will be solved quickly enough, and then we will be able to deploy small binaries :)
- rapsey 8y ago> there's potential :) To be owned by Larry Ellison.
- wink 8y agoValid point, but to a degree I still see this for the whole Java ecosystem. Many people over the last 20 years were dissuaded from using Java just because of the looming Oracle "threat". I'm not advocating to make GraalVM a mandatory dependency, just saying this could be an interesting project for people who are annoyed at the status quo, and there are a lot of startup speed complaints. Unfortunately my day job has nothing to do with any JVM or Clojure anymore, so I can't divert any time there.
- zcam 8y agoOracle didn't own java 20 years ago :) That said there's a lot of FUD around Oracle ownership nowadays but most of it is moot since OpenJDK is the fundation of Oracle's Java.
- dnomad 8y agoGraalVM is itself an open-source project that is licensed under the exact same license as OpenJDK [1]. Feel free to download it and build it yourself to be extra sure [2]. All the FUD around this stuff and Oracle is a bit comical. It's all... right there. [1] https://www.graalvm.org/docs/faq/ https://www.graalvm.org/docs/faq/ [2] https://github.com/oracle/graal https://github.com/oracle/graal
- zcam 8y agoRight it's also gpl my bad. The fact you can download and build it doesn't mean much in general tho.
- ptx 8y agoBut it's not "all" there - some things are reserved for the enterprise edition. So if people start adopting it now in the hope that its remaining technical limitations will eventually be adressed, we might discover that the improvements only apply to the EE version, while the open source version is kept more or less where it is to encourage people to pay up.
- bad_user 8y agoGraalVM is very cool, but AOT compilation has caveats too. No more profiling and optimizing the code at runtime for example. I wonder what the performance impact will be for Clojure code.
- pjmlp 8y agoThat is why AOT compilers also support PGO, including Graal.
- chii 8y agoFor many real world applications, you'd need to load classes that isn't known at compile time (e.g., a user supplied database jdbc connector). I wonder how AOT can deal with this scenario. Is it possible to AOT but still have the fallback of classloading at runtime?
- zebraman 8y agoPersonally, I wonder why class-loading is not possible. In the end either a class exists in the closed-world that existed when the project was compiled, or it does not. Of course you cannot change the JDBC connector after it was compiled! Maybe they could add a whitelist of "known" entry-points for class loading, as to avoid going through a list of 10,000 inner classes that existed at compile time but nobody will ever instance by name.
- jcelerier 8y ago> In the end either a class exists in the closed-world that existed when the project was compiled, or it does not uh ? no, new classes are added at runtime all the time - at least in C++, dynamic loading of plug-ins is extremely common
- zebraman 8y agoWhat I'm saying is that it breaks when you do a Class.forName(...), while if such class is known to exist at compile time, it is the same as a switch statement on the class name that returns a new object of the same type; and that second form would be a valid operation.
- jcelerier 8y ago> What I'm saying is that it breaks when you do a Class.forName(...), but you don't do this. you register the classes according to what is on your file system and you load one that matches your criterions or you ask your user to choose one in a UI of some kind.
- 8y ago
- truth_seeker 8y agoSupport for Reflection and Dynamic class loading isn't possible yet, which could be a big downside. I hope 1.0 GA release lands with it.
- zebraman 8y agoReflection is partially emulated, IIRC.
- pankajdoharey 8y agoGraalVM is very impressive. But clojure is very much associated with Java/JVM Ecosystem which makes it very hard to convince people to use it. My ruby friends would say oh i cant install clojure because i have to install JVM. Clojurescript like lumo or planck is still better, but it isnt a real backend solution. Clojurescript is great for the frontend though. I think clojure needs a native solution written in Clojure + LLVM that leverages existing C-libs. A seperate JIT/compiler that is not JVM, that is not a language with Borrowed GC + VM.
- rhencke 8y agoGraal is able to produce native, statically linked executables that do not require a JVM installed to run. See the native-image component of Graal.
- unmole 8y agoI don't understand this sentiment. How is installing JRE any diffierent than installing Ruby?
- jxub 8y agoIt means installing a big runtime they aren't familiar with, and getting their feet wet with a huge ecosystem which spans from weird stacktraces to the standard libraries and beyond, and is associated (somehow wrongly) with boring code and old enterprise solutions.
- olieidel 8y agoThe almost exact same could be said for Ruby and frankly, any other programming language which has stacktraces and a standard library.
- szemet 8y agoClojure stack traces are usually long and somewhat leaky, they are hard to read without (and sometimes even with) preexisting knowledge about Java / JVM / Clojure implementation details. https://ioavisopretty.readthedocs.io/en/v0.1.34/exceptions.html https://ioavisopretty.readthedocs.io/en/v0.1.34/exceptions.h... https://lispcast.com/clojure-error-messages-accidental/ https://lispcast.com/clojure-error-messages-accidental/
- divs1210 8y agoThe native binary produced by Graal CE does not support runtime optimizations - that is EE only. As such, native binaries will start faster, but run slower. https://github.com/oracle/graal/issues/447#issuecomment-399524000 https://github.com/oracle/graal/issues/447#issuecomment-3995...
- crudbug 8y agoI think .Net folks are also doing similar things on CoreRT side ?
- pjmlp 8y agoYes, however.NET has standard AOT support as part of its toolchain. NGEN, MDIL for WP 8.x, .NET Native for UWP, Xamarin AOT, Unity IL2CPP, and the internal compilers used at Singularity and Midori.
- dancek 8y agoI saw the talk live last Friday in ClojuTRE. Someone asked about performance, and IIRC the speaker said that a GraalVM-built native binary tends to run about 50% slower than JVM for long-running tasks. For some purposes this matters and for some others it doesn't. I can certainly see the benefit of quick startup for e.g. CLI tools. And for servers, the security benefit of running a single standalone binary blob inside a multistage Docker container might be easily worth it.
- mark_l_watson 8y agoAt a minimum this will be very useful for command line utilities: small memory footprint and good runtime performance. I used to use Gambit Scheme for command line utilities for the same reasons.