https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
t

Tlaster

06/20/2022, 2:51 AM
Are there any sample about using compose desktop with R8?
1
r

romainguy

06/20/2022, 2:55 AM
R8 converts directly to dex byte code I believe so that wouldn't work for desktop
t

Tlaster

06/20/2022, 3:02 AM
compose desktop release package file is 100MB+, so I wonder if is there any way to reduce the package file size
r

romainguy

06/20/2022, 3:05 AM
I'd be surprised if the binary size is mostly from .class files. It's much smaller on Android. I bet a lot of it comes from native libraries. There might also be other stuff included that shouldn't be there. Have you peeked inside the jars?
t

Tlaster

06/20/2022, 3:17 AM
I check the installed folder (on mac is xxx.app open as a folder, not the uber jar) and most of the sizes come from the compose framework, a simple skiko can take up to 30MB.
r

romainguy

06/20/2022, 3:19 AM
Skiko can't be removed by R8, it's absolutely necessary but I'm sure jetbrains could make it smaller
I also imagine a JRE is included?
t

Tlaster

06/20/2022, 3:36 AM
Yes, a complete JRE is included
r

romainguy

06/20/2022, 3:39 AM
Yeah so R8 is really not where you are going to get real savings
e

eygraber

06/20/2022, 7:12 AM
I vaguely remember a discussion here about using proguard for compose desktop
h

hfhbd

06/20/2022, 7:21 AM
R8 supports converting to java class code, but you still need skiko and the included JRE, so I don't think reducing size is significant.
👍 1
👍🏻 1
t

Tlaster

06/20/2022, 7:31 AM
So we can only use proguard to reduce the size? 100MB+ for a simple desktop app is quite large for me.
m

Michael Paus

06/20/2022, 8:12 AM
I’d like to warn a little bit because hunting for ever smaller distribution sizes easily becomes a kind of fetish. The sizes may sound large for mere hello world programs but serious application are often much larger than this and nobody cares.
m

mcpiroman

06/20/2022, 8:48 AM
I'm using Proguard but it does not make much savings in the size. It's the packed JRE that takes 68MB in my case. And it should be somehow possible to reduce that - e.g. JB Toolbox had manage to go down to 43MB. So I'd explore that direction first. But still, there is more work to do in the CfD itself - e.g. there is a duplicated 1MB jar file as reported here
m

Michael Paus

06/20/2022, 9:18 AM
Did you explicitly specify a list of the JRE modules in your desktop
build.gradle.kts
which you really need for your app? See: https://github.com/JetBrains/compose-jb/blob/master/tutorials/Native_distributions_and_local_execution/README.md#configuring-included-jdk-modules Something like:
Copy code
compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "jvm"
            packageVersion = "1.0.0"
            modules("java.base","java.naming","java.prefs","java.scripting","java.sql","jdk.jfr","jdk.unsupported","jdk.unsupported.desktop","<http://jdk.crypto.ec|jdk.crypto.ec>","jdk.localedata")
        }
    }
}
m

mcpiroman

06/20/2022, 10:23 AM
Yes, I have. But those do not make much difference either.
a

alexey.tsvetkov

06/20/2022, 10:33 AM
Soon (in 1-2 weeks I hope), we will release the simplified Proguard integration for Compose Desktop Gradle plugin. After that we might look into R8 as well (the configuration should be almost 1-to-1 as proguard), AFAIK it should work with class files, and even supports reading JDK 9+ module files (jmod). My testing with our standard examples (widgets gallery & code viewer) showed noticeable reduction in distribution sizes. For Widgets Gallery: • Uncompressed app directory: 129.7 Mb -> 96 Mb (-25%); • Compressed
dmg
installer (Mac): 76Mb -> 40 Mb (-47%). Code viewer example showed similar reductions. Of course reductions are going to depend on an amount of actually used dependencies, but it seems worth it for small & medium sized apps.
K 12
👍 4
🙏 6
r

romainguy

06/20/2022, 4:21 PM
Beyond size reduction, R8 provides nice benefits in terms of code organization and optimization when it comes to Compose. In particular it can merge lambdas into fewer classes which helps with startup times, etc.
91 Views