Nucleus
Performance & native

Startup optimizationNew

Turn on the nucleusOptimization pack to shorten JVM startup and lower idle memory, and package the app with the current OpenJDK through lastJdk.

View as Markdown

nucleusOptimization is a set of JVM packaging defaults tuned for desktop apps. It is off by default, and your source code stays the same when you turn it on.

build.gradle.kts
nucleus.application {
    nucleusOptimization = true
    nucleusOptimization { idleGc = false } // optional: force one knob on or off
}

Each knob is a Boolean?: null follows the master switch, true or false forces it. You can also leave the pack off and turn on a single knob.

Knobs

KnobEffect when on
serialGcUses the Serial collector when garbageCollector is unset.
compactHeapAdds -Xms32m and -XX:MaxRAMPercentage=25, each one only if jvmArgs does not already set it.
singleJarFlattens the runtime JARs into one JAR. With ProGuard, it sets joinOutputJars instead.
idleGcCollects garbage while the app sits unused. See Idle GC.
lastJdkPackages and runs the app with OpenJDK 27. See Package with the latest JDK.
partialRedrawRepaints only what changed in each frame. See Rendering performance.
mallocArenasLinux: caps glibc's malloc arenas at 2 to lower resident memory. See Cap glibc malloc arenas on Linux.

The pack never replaces a value you set (garbageCollector, javaHome, -Xms, -XX:MaxRAMPercentage), and it does not enable the AOT cache or ProGuard. serialGc, compactHeap, singleJar and lastJdk do not apply to a GraalVM native image.

Package with the latest JDK

With lastJdk on, the plugin downloads OpenJDK 27 GA (BellSoft Liberica JDK 27 on Intel macOS and Windows on ARM) the first time a packaging or run task needs it. The app ships with that runtime; your jvmToolchain(...) stays as it is.

  • Set NUCLEUS_JDK_HOME to a local JDK 27 to skip the download.
  • An explicit javaHome disables lastJdk.

Idle GC

Idle GC runs System.gc() right away when a window is minimized, or 3 s after every window has lost focus. Startup never triggers one. It covers the windows nucleusApplication opens and works in native images too. Pass -Dnucleus.optimization.idleGc=false to turn it off for one run.

Cap glibc malloc arenas on Linux

glibc creates up to 8 malloc arenas per CPU core, and each one keeps the memory it once held. A desktop app runs many threads (JVM, Skia, GPU driver, coroutines), so its resident memory ends up far above what it uses. mallocArenas caps the arenas at 2 when the app starts, in JVM apps and native images alike.

build.gradle.kts
nucleus.application {
    nucleusOptimization { mallocArenas = true }
}
  • -Dnucleus.optimization.mallocArenaMax=<n> in jvmArgs sets another cap, and 0 turns it off.
  • A MALLOC_ARENA_MAX variable, or glibc.malloc.arena_max in GLIBC_TUNABLES, always wins.
  • It has no effect on macOS, Windows, or a musl libc.

What's next

Was this page helpful?
Edit on GitHub

Last updated on