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

Reduce native binary size #259

Open
lppedd opened this issue Sep 15, 2022 · 1 comment
Open

Reduce native binary size #259

lppedd opened this issue Sep 15, 2022 · 1 comment
Assignees
Labels
relates-to: graal status: under consideration The issue is being considered, but has not been accepted yet

Comments

@lppedd
Copy link

lppedd commented Sep 15, 2022

Issue description

Hi everyone!
Taking the Micronaut Picocli example code and compiling it to native - on Windows - outputs a binary file of 50 MB.
Are there tricks to make it smaller?
For example, comparing to a Quarkus CLI alternative, it's 20 MB bigger.

Now, on a more realistic example, let's take these Gradle dependencies:

dependencies {
  annotationProcessor("org.projectlombok:lombok:1.18.24")
  annotationProcessor("info.picocli:picocli-codegen")

  // Added afterwards
  implementation("one.util:streamex:0.8.1")
  implementation("com.github.javaparser:javaparser-core:3.24.4")
  implementation("org.eclipse.jgit:org.eclipse.jgit:6.3.0.202209071007-r")
  implementation("me.tongfei:progressbar:0.9.4")

  // Already there at project initialization
  implementation("info.picocli:picocli")
  implementation("io.micronaut.picocli:micronaut-picocli")
  implementation("jakarta.annotation:jakarta.annotation-api")

  compileOnly("org.projectlombok:lombok:1.18.24")
  runtimeOnly("ch.qos.logback:logback-classic")

  testImplementation("org.mockito:mockito-core")
  testImplementation("io.micronaut:micronaut-http-client")
}

configurations.implementation {
  exclude group: "io.micronaut", module: "micronaut-http"
  exclude group: "io.micronaut", module: "micronaut-http-client"
  exclude group: "io.micronaut", module: "micronaut-jackson-databind"
}

The above will output a 44 MB executable.

@sdelamo sdelamo self-assigned this Jul 26, 2023
@sdelamo sdelamo removed this from 4.0.2 Release Jul 28, 2023
@sdelamo
Copy link
Contributor

sdelamo commented Jul 31, 2023

I generated a native executable for MacOS Apple Silicon Mac with Micronaut Framework 4 and the following build (probably the smallest build config possible):

plugins {
    id("com.github.johnrengelman.shadow") version "8.1.1"
    id("io.micronaut.application") version "4.0.2"
}

version = "0.1"
group = "nativetest"

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor("info.picocli:picocli-codegen")
    implementation("io.micronaut.picocli:micronaut-picocli")
    runtimeOnly("ch.qos.logback:logback-classic")
}


application {
    mainClass.set("nativetest.NativetestCommand")
}
java {
    sourceCompatibility = JavaVersion.toVersion("17")
    targetCompatibility = JavaVersion.toVersion("17")
}

micronaut {
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("nativetest.*")
    }
}
du -h build/native/nativeCompile/nativetest
 45M	build/native/nativeCompile/nativetest

@micronaut-projects/core-developers is there anything we can do to reduce the binary size? Micronaut Picocli depends on Micronaut Inject.

@sdelamo sdelamo added relates-to: graal status: under consideration The issue is being considered, but has not been accepted yet labels Jul 31, 2023
@sdelamo sdelamo moved this to In Progress in 4.0.3 Release Jul 31, 2023
@sdelamo sdelamo removed this from 4.0.3 Release Aug 2, 2023
@sdelamo sdelamo removed this from 4.1.0 Release Sep 1, 2023
@sdelamo sdelamo removed this from 4.2.0 Release Nov 12, 2023
@sdelamo sdelamo removed this from 4.3.0 Release Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relates-to: graal status: under consideration The issue is being considered, but has not been accepted yet
Projects
None yet
Development

No branches or pull requests

2 participants