Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Thomas-Vos
Copy link
Contributor

@Thomas-Vos Thomas-Vos commented May 28, 2022

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 Thomas-Vos marked this pull request as draft May 28, 2022 19:03
@igordmn
Copy link
Collaborator

igordmn commented Jun 17, 2022

It will be great to have this feature.

@AlexeyTsvetkov, could you look at the PR?

@eskatos
Copy link

eskatos commented Jun 28, 2024

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
Copy link

eskatos commented Jul 1, 2024

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" } }
        }
    }
}

@Thomas-Vos
Copy link
Contributor Author

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

@eskatos
Copy link

eskatos commented Jul 22, 2024

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.

@Thomas-Vos
Copy link
Contributor Author

Thomas-Vos commented Aug 8, 2024

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 Thomas-Vos changed the title Add option to enable Class data sharing (CDS) CMP-5906 Add option to enable Class data sharing (CDS) Aug 8, 2024
@Thomas-Vos Thomas-Vos marked this pull request as ready for review August 8, 2024 14:47
@Thomas-Vos
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants