compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

CMP-5906 Add option to enable Class data sharing (CDS)

Open Thomas-Vos opened this issue 3 years ago • 7 comments

CMP-5906 Add option to enable Class data sharing (CDS)

Alternatively this could be enabled by default, what do you think?

This PR adds an option for CDS, not for AppCDS.

AppCDS is probably not worth it. Generating it at first startup slows down the startup. So it should probably be generated at install time somehow (not sure if even possible, and would take too much time). Generating it at build time in this gradle plugin would be another option (which I think is best), but that would increase app size. AppCDS would require more investigation before adding it. I think what would be ideal, is that the gradle plugin would launch the app in the background when building, and maybe run some sort of compose test to warm up code. Then exit and include the generated file in the archive. Does this make sense?

Thomas-Vos avatar May 28 '22 18:05 Thomas-Vos

It will be great to have this feature.

@AlexeyTsvetkov, could you look at the PR?

igordmn avatar Jun 17 '22 07:06 igordmn

AppCDS makes starting up Compose Desktop applications muuuuuch faster. I tried to fiddle around to enable this without a patch but could not figure out a way. Could this be considered again? Pretty please :)

eskatos avatar Jun 28 '24 15:06 eskatos

For readers who want to enable CDS Today, here's a dirty workaround:

afterEvaluate {
    tasks.named<AbstractJLinkTask>("createRuntimeImage") {
        freeArgs.addAll("--generate-cds-archive")
        val stripNativeCommands = this::class.java.methods
            .single { it.name.startsWith("getStripNativeCommands") }
            .invoke(this) as Property<Boolean>
        stripNativeCommands.set(false)
        doLast {
            destinationDir.get().dir("bin").asFile
                .walkBottomUp()
                // Windows JVM has its .ddl files in bin/
                .filter { it.isFile && it.extension != "dll" }
                .forEach { check(it.delete()) { "Unable to delete $it" } }
        }
    }
}

eskatos avatar Jul 01 '24 08:07 eskatos

Nice, I am curious what AppCDS could do for a compose app in addition to CDS.

Thomas-Vos avatar Jul 17 '24 18:07 Thomas-Vos

I got AppCDS working on top of CDS. I did not measure precisely but it feels snappier.

compose.desktop {
  application {
    nativeDistributions {
      jvmArgs += "-Xlog:cds=error" // change to 'debug' to get more info
      jvmArgs += "-Xshare:auto"
      jvmArgs += "-XX:+AutoCreateSharedArchive"
      jvmArgs += "-XX:SharedArchiveFile=path/to/app-cds.jsa"
    }
  }
}

One painful thing is that you need to provide a path relative the the JVM working directory for the jsa file.

eskatos avatar Jul 22 '24 08:07 eskatos

I got AppCDS working on top of CDS.

I just gave it a try, and it seems to generate the app-cds.jsa as expected. However, the first startup is now very slow, so that is pretty bad. I guess it would be better to somehow generate this file in the gradle plugin automatically and include it at build time. (see PR description for more info)

Thomas-Vos avatar Aug 08 '24 00:08 Thomas-Vos

Hi @igordmn, could you please review this or assign it to the correct person?

Thomas-Vos avatar Aug 08 '24 14:08 Thomas-Vos