I managed to get Compose working with GraalVM on m...
# compose-desktop
u
I managed to get Compose working with GraalVM on macOS (which seems to be the hardest platform to get working), Windows and Linux. Even though Leyden exists, I find it useful for apps that require very low RAM usage. I wonder if it’s worth implementing it in Nucleus. https://github.com/kdroidFilter/compose-graal-vm Here's the repo for a sample app;
😮 12
🎉 12
yes black 2
mother of god 3
s
what was necessary to achieve it? I don't know much about it but from past messages it seemed like one of the main issues was that AWT was not supported by graalvm, so a different UI toolkit would be needed.
u
I used the Liberica native toolkit that support awt
s
also, do you have a RAM comparison without using graal?
u
I know it's around 220-250, but I'll test that precisely.
👍🏻 1
I'll first try to see if it works under Windows and Linux.
s
my live app easily exceeds 600MB, I'm all for cutting that down 😅
u
I don't know if it will change much in your case; you might reach 500MB, but if your app is CPU-intensive, you'll also have much lower performance. I think it's a small gain compared to everything you lose.
This is mainly for small apps that need to stay open all the time; I'm thinking of apps like JetBrains Toolbox, which in my opinion uses too much RAM for an app that's constantly running.
s
yeah that makes sense. I wasn't aware of performance implications
u
I think it's good for applications that are mostly pure UI; I think we'll get better performance with pure UI, but certainly not for apps that need high computing power.
on windows it's very impressive
😲 1
it's without graalvm
Another very interesting point is that the native graalvm executable, once compressed in zip, is approximately 25MB.
With packagers like NSIS that support higher compression formats, it can be very interesting.
I'm going to try to compile everything into a GitHub runner matrix
I think the biggest sticking point will be creating a stable decorated window that doesn't use the JBR APIs.
s
oh JBR is not an option for graalvm? how do the startup times compare to AOT cache? similar or is one significantly faster? (haven't tried leyden myself yet)
u
No, JBR doesn't support GraalVM; I'd say there's a 20 to 30% difference
👍🏻 1
Leyden remains very fast, and that's what I use for my large applications.
I tested it on a real mini application and it's very impressive.
https://github.com/kdroidFilter/compose-graal-vm Here's the repo for a sample app
t
Nice, I'm actually using GraalVM on Windows and Linux in production for two of my apps. It's working great, but writing the agent tests was lots of work to handle edge cases. For macOS I decided to use kotlin native instead.
u
@Thomas Do you use JNA a lot?
s
Really cool exploration! Sadly no JBR == no Jewel :(
u
@seb Is jbr not only necessary for the decorated window?
s
At this point there are so many things that won't work properly outside the JBR, like font loading on Windows and Linux doesn't work correctly on other JVMs
There is no way to match a Compose font family and an AWT font because JVMs use the wrong ttf field as font name lol
HiDPI/density support is also missing/lacklustre on other JVMs
m
@seb What exactly isn't working with HiDPI? I haven't noticed any problems on my retina macs with Zulu 25 for example. Do you have issue numbers?
s
I have been told it's primarily when you have multiple screens with different densities (and especially on Linux)
On other VMs I also have seen bitmap corruptions and weird visual glitches over the years
u
@seb Theoretically, we should be able to do all of this via JNI, right? Personally, using GraalVM is only really worthwhile on Windows, because Windows is really, really (like, really) slow at compiling JIT , whereas Leyden on Mac and Linux is instantaneous.
s
Those may be fixed or not
I haven't used Leyden @אליהו הדס so I have no context here but yeah, at least on windows it should be possible to use JNI for some of these issues. But you can't hot-patch the JVM you're running on to parse TTF correctly for example
And in general, if you look at the JBR API GitHub repo you get an idea of what is missing in terms of features on other JVMs
💯 1
(I also suspect there's quite a different level of maintenance of the UI stack and its perf on JBR compared to other JVMs but I have no hard data here)
u
@seb But the issue with TTF files is only relevant if I want to load system fonts, right?
m
I just don't like the idea of the "write once, run anywhere" to become "write once and only run on JBR" 🧐.
💯 2
u
@Michael Paus No, I disagree. OpenJDK hasn’t cared about desktop apps with the JVM for the past 15 years.
Have you seen the system tray? It’s the same one from Windows XP.
maybe windows 95
s
Yeah that is the sad reality, JBR is the only JVM that cares at all about desktop UI.
😭 2
💯 1
Swing code has been largely left untouched in the other JVMs since the mid-00s
JetBrains has an obvious interest in keeping their JBR working well for UI and do a ton of testing and continuous improvements — the only ones as far as I know who invest on it
Last year they did a ton of work to enable proper a11y/screen reader support on Linux for example, which has never worked well on JVM
Maybe some of it will eventually make it into other JVMs, but it is unlikely — not because JetBrains don't care, but because by and large other JVMs do not care about mainlining
The JBR fundamentally exists because others have stopped caring
u
Personally, I don't understand why Compose doesn't recommend JBR. I saw in the accessibility code that it uses JBR and provides fallbacks if it's a different JVM, but this isn't mentioned anywhere.
s
Last I checked they do not want core Compose to depend on JBR
m
I don't disagree with the facts but nevertheless I also don't like this move away from a unified Java platform. Getting something into the JDK is harder than just doing it outside but at leaset one should try.
s
Not as a hard dependency
Michael, the people working at JetBrains used to work at Sun in St Petersburg, you think they wouldn't?
If Oracle is not receptive, they can't force things in
Again, JBR exists not because JetBrains doesn't care, but because others do not
👍 1
💯 3
👍🏾 1
u
Not as a hard dependency
But why? What's the problem with forcing the use of JBR? In the Compose plugin, I saw code for JDK <16.
s
They see things like Michael I guess 😄
I don't know, they might have an official stance I am not aware of, and do not want to put anything into anyone else's mouth here
My read of the situation is that above
u
I think it's better to focus on a single platform, simplify the code, and add more features. Decorated windows are, for me, a must-have that's hidden in the billions of lines of IntelliJ code without being documented.
s
We have extracted the core bits in Jewel at least 😄
👍 1
s
Hot reload already depends on the JBR. And since we need to bundle a JVM anyway I don't see an issue either
s
Hot Reload technically depends on DCEVM, the fact that JBR is the only JVM that implements it is again this
Also to note, Hot Reload is not maintained by the core CMP team, but by the wider Kotlin team
u
On macOS, I ran the demo of Jewel with my own implementation of a decorated window, and it seems to work very well; I'll test it with GraalVM.
🔥 1
it seem to work
🇫🇷 1
🇮🇱 1
s
nice! the dropdown in the title bar looks a bit odd but that's probably not graalvm
u
no it's my decorated window 🙂
but you load all your icons via reflection !
If we had a plugin like this that could automatically resolve all the reflection without having to do it manually with an agent, that would be great; otherwise, it's really only for power users.
(I'm living in Israel 15 years ago and i'm 29 🙂 )
🔥 1
s
Icon loading is being redone at the IJPL level to better support Compose/Jewel :)
👍 1
👍🏾 1
u
I don't know if it's clear in the video, but the GraalVM version (on the left) has a lot of trouble managing the lazy column of 1 million elements, unlike the JVM version which handles it without any problem. In fact, as you can see, the GraalVM version completely crashed. So, as I said, it should be reserved for small applications that need to start instantly and have very low RAM usage, but otherwise the JVM remains much more efficient.
@seb jewel + graalvm on windows 🙂
🔥 1
s
Awesome stuff mate, thanks for pushing the envelope ❤️
u
Yes! 🙂 I'll publish all of this soon.
But it took me 4 hours with your font loading system under Windows! 😵‍💫
s
It's a pain I know
😶 1
Took me weeks to figure out to begin with
u
I would like to try compiler a real application that uses Jewel with GraalVM
I certainly won't distribute it, but I want to see if it's possible; it'll be fun.
I could write an article about it 🙂
s
I'd love to read it
🙌 1
u
I wrote my first article on Compose Desktop a while ago; I think you'll like it.
@seb I managed to get HDPI support under Windows and Linux with GraalVM ! 🎉
I’m starting to believe that it could really be usable
what is funny, is that the application detects the change of theme before the windows apps 🙂
😂 2
s
Awesome!
Waiting for a blog article and a ready-to-use library 😄
😅 1
1
Wonder if you can also get GraalVM not to crash with larger apps
u
I think that if we use aot, we should not load 1 million objects at once but pagination 😅
even in a JVM, I am not sure that it is a good practice 😬
s
Ehehe well that is an intentional stress test :P
u
I understood well 😅
e
Thanks for this thread guys!
K 2
u
@seb I managed to compile an average app that uses Jewel and Lucene with graalvm 🙂 and for the moment no bug has been reported
🔥 1
and this is with jvm
afterward I know that a lot of dev use koin, and I wonder if it will break with graalvm, but since I’m using metro there’s no problem, personally I don’t have anything to test with koin
s
Same here, Metro ftw
🚋 3
1
u
my intuition is that it is perfectly possible to make a plugin that compiles the app with graalvm and that would work out of the box for all kmp libs since they do not use reflection in the vast majority of cases, and when we have jvm only dependencies, it would need to be configured manually, I think that could be interesting. Compose would directly attack flutter in the size of binaries, the startup speed, and the perfs in pure ui on desktop, and would surpass it. (except in the size of the binary) , it would be cool to find a sponsor
for now I just think about publishing an experimental version of nucleus that will support graalvm and that will ask the developer to be extremely careful
On the left it is with graalvm, on the right it’s jvm + leyden with proguard (jvm about 40mb, leyden 20mb)
I also note that the graalvm compilation is faster than the progard optimization
m
What has actually been changed so that this seems to be working now? Several years ago I made some efforts myself to get that working but at that time it seemed to be not possible. See: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1675614566722809?thread_ts=1675578052.700349&amp;cid=C01D6HTPATV
u
@Michael Paus maybe it improved with the JDK 25 from liberica
And I don't think it was configured correctly; the libraries need to be in very specific locations, it's a bit strange even, it took me a while to find the right configuration.
All the libs must be located next to the executable, except for jawt, if I remember correctly, which must be in a lib folder. I wonder if such a configuration will be accepted by the Mac App Store.
m
As far as I understand the issue binary lib files must come with the application and must reside inside the app-folder. A common scheme like extracting them at run-time from a jar and place them into a temporary folder doesn't work.
u
Yes, that's it. My Nucleus plugin will handle that out of the box. The question is, will it be accepted by the Mac App Store?
m
I don't know for sure because I don't use the App Store. I just stick to the above rules and notarize my apps for self-distribution. That works. I don't know if notarization has the same requirements as the App Store here.
u
yes it's fine for notorization but native libs have to be in Content/Framework for the mac app store
I don't know if it's just a convention
m
At least for notarization they don't have to be in Content/Framework.
a
Personally, I don’t understand why Compose doesn’t recommend JBR. I saw in the accessibility code that it uses JBR and provides fallbacks if it’s a different JVM, but this isn’t mentioned anywhere.
We just haven’t made the decision, officially. Personally, I would recommend JBR for CfD apps, and I use it myself in my pet project.
u
The most annoying thing is the HDPI; nowadays all laptops have an HDPI display. If it's Windows, then it's blurry, and if it's Linux, it's extremely small. JBR isn't an option in my opinion.
On Windows, I've seen that with the Liberica JDK, I don't have this problem, but they've done a lot of optimizations for Swing and JavaFX; I don't know about other JDKs. But with linux only jbr support hdpi
s
Yeah realistically you can only get consistently good results across platforms with the JBR.
u
We're still waiting for touchscreen support 😬
I'm getting loads of msg saying the touchscreen isn't working properly. I tell them that the day Apple releases a touchscreen MacBook Pro, JB will support it too 😂
😂 1
m
Maybe Apple was listening to you:

https://www.youtube.com/watch?v=5AAjWlomscw

a
god no
u
god no
Because you know you'll have to put up with the touchscreen, or because a laptop with a touchscreen is absolutely awful and useless?
a
Imagine the amount of bugs you can have when you have a screen with any number of touch pointers PLUS a mouse pointer.
💯 1
Because you know you’ll have to put up with the touchscreen, or because a laptop with a touchscreen is absolutely awful and useless?
Both
😅 1
u
Steve Jobs is missed; they are tarnishing his name. 😭
m
Don't blame me. I am just the messenger 😇. I agree with you but when Apple comes up with that we will sooner or later have to cope with it.
u
@Michael Paus Well yes, in two years, we’ll all have touch-screen Macs and we’ll say it’s amazing, even a revolution.
That’s exactly what I’m saying: as long as Apple doesn’t release a touch-screen Mac, then touch-screen laptops “don’t exist,” so there’s no need to bother implementing it.
@seb Were you able to test Jewel with GraalVM?
s
No I do not have time for that these days, I may in the future but I'm pretty swamped 🙂
u
thank you very much! it’s mainly the workaround that I did regarding the fonts, I wonder if it’s problematic what I did
s
If it works on Windows it's probably fine 😄
macOS is the one that ~works on all OSes since JVMs use the system APIs for fonts instead of manual parsing
Windows/Linux the JVM manually parses (badly)
u
https://github.com/kdroidFilter/Nucleus/tree/main/graalvm-runtime/src/main/java/io/github/kdroidfilter/nucleus/graalvm/font if you have the time to verify this, if it’s correct and doesn’t generate bugs, that would be super cool
s
I did that work 2y ago so I don't remember all the subtleties 😄 I don't want to commit to it since I honestly don't know when I'll have time — I am pushing back on reviews at work too and have like 16 pending Jewel PR reviews to do 🫠
I'd rather not say I'll do it when I don't know when
Out of respect
u
Thank you very much. In any case, I think that since I'm an adventurer, the next version of my app will be distributed with GraalVM, so we'll see 😅
🔥 1
s
Best of luck 🙂 I'll be keeping an eye on your progress for sure 🙂
🙌 1
133 Views