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.
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.
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
| Knob | Effect when on |
|---|---|
serialGc | Uses the Serial collector when garbageCollector is unset. |
compactHeap | Adds -Xms32m and -XX:MaxRAMPercentage=25, each one only if jvmArgs does not already set it. |
singleJar | Flattens the runtime JARs into one JAR. With ProGuard, it sets joinOutputJars instead. |
idleGc | Collects garbage while the app sits unused. See Idle GC. |
lastJdk | Packages and runs the app with OpenJDK 27. See Package with the latest JDK. |
partialRedraw | Repaints only what changed in each frame. See Rendering performance. |
mallocArenas | Linux: 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_HOMEto a local JDK 27 to skip the download. - An explicit
javaHomedisableslastJdk.
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.
nucleus.application {
nucleusOptimization { mallocArenas = true }
}-Dnucleus.optimization.mallocArenaMax=<n>injvmArgssets another cap, and0turns it off.- A
MALLOC_ARENA_MAXvariable, orglibc.malloc.arena_maxinGLIBC_TUNABLES, always wins. - It has no effect on macOS, Windows, or a musl libc.
What's next
- AOT cache: skip JVM warmup with a Project Leyden cache.
- GraalVM Native Image: compile the app to a native binary.
- Gradle DSL reference: every property of
nucleus.application.
Last updated on
Runtimes and performance
Build the same Kotlin source as a GraalVM native image or as a JDK image with an AOT cache, pick the right one, and detect the runtime from code.
Rendering performance
Repaint only what changed with partial redraw, see each frame's damage with the debug overlay, count recompositions, and let idle windows give their GPU memory back.