Repository navigation
JVM AOT cache: a training task, a Jib image, and a Dagger pipeline - #73
Open
rocketraman wants to merge 4 commits into
Open
rocketraman wants to merge 4 commits into
rocketraman wants to merge 4 commits into
Conversation
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
The bootable.aot-cache plugin, in a new build-logic included build, adds an aotCache task to an application: it runs the installed distribution once, by its start script, on the project's toolchain, with -XX:AOTCacheOutput, waits for Bootable's "=> Running" line, sends the requests given to it, and stops it with SIGTERM, so the JVM writes the cache as it exits. - AotCacheTraining runs any command, so a container's training can use it too. - The task reruns when the installed jars' modification times change, as the JVM checks them against the cache. - The vanilla server-ktor-db example trains with a few requests, so the cache covers the request path too.
The cache is trained in a container of the image itself, so it matches the image's JDK build and class path: jibBuildTar builds the image without a cache, the container runtime loads it, aotCache runs it with -XX:AOTCacheOutput and the cache's directory mounted, and jibDockerBuild (or jib) builds the final image with the cache as one more layer and -XX:AOTCache in its JVM flags. - Jib's images are reproducible, so the final image's jars match the training's, modification times included. - containerizingMode is packaged: the JVM won't use a cache with a non-empty directory on the class path. - -PcontainerCli=podman runs it with Podman.
How to produce the cache and run with it, what has to match for the JVM to use it, the measured start times with and without it, and how the Jib example trains it in its own image.
rocketraman
force-pushed
the
rg/aot-cache
branch
from
November 18, 2026 05:53
95825ba to
2a27e25
Compare
A Dagger module, in Dang, that builds the vanilla app with Gradle in a JDK 25 container, installs it into a JRE container, trains the AOT cache in a container of that runtime, and adds the cache to the same runtime as the image, so the JDK build and the jars' modification times match by construction. check runs verify, which fails unless the image loads most of its classes from the cache; the image is exported, never pushed. - It follows the Dagger 1.0 beta layout: dagger.toml, dagger.lock, and the module in .dagger/modules. .mise.toml provides the stable CLI, and DAGGER_X_RELEASE has it run v1.0.0-beta.28. - dagger.lock pins the JDK and JRE images by digest. - The build uses Gradle's build cache, in the Gradle user home's cache volume, without turning it on for every build. - The training sends its requests through bash's /dev/tcp, as the JRE image has no curl, and unsets the OTEL_* variables Dagger sets, so the app exports nothing to Dagger's collector, and trains as it runs in production. - The README says when to use it rather than the aotCache task or Jib.
rocketraman
force-pushed
the
rg/aot-cache
branch
from
November 18, 2026 05:56
2a27e25 to
95c8b88
Compare
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes JVM AOT caches (JEP 483/514, JDK 24+) easy for Bootable apps, three ways: a Gradle task, a Jib image, and a Dagger pipeline.
What's here
bootable.aot-cache(newbuild-logicincluded build,AotCache.kt): it adds anaotCachetask to anyapplicationproject. The task runs the installed distribution by its start script, on the project's Java toolchain, with-XX:AOTCacheOutput. It waits for Bootable's=> Runningline, sends any configured training requests (request(method, url, body),rounds), stops the app with SIGTERM, and checks that the cache was written. The app's output goes tobuild/aot/<name>.aot.log.Vanilla
server-ktor-dbtrains with a small PUT/GET/DELETE/metrics workload.examples/server-ktor-db/jib: an image with the cache in it, trained inside the image itself.jibBuildTarbuilds the image without a cache, then it is loaded.aotCacheruns it in a container with-XX:AOTCacheOutputand a mounted directory.jibDockerBuild/jibthen add the cache as an extra layer, with-XX:AOTCacheinjvmFlags.The
server-ktor-dbDagger module (dagger.toml,dagger.lock,.dagger/modules/server-ktor-db/main.dang): a Dagger module in Dang, on Dagger v1.0.0-beta.28..mise.tomlprovides the stable CLI and setsDAGGER_X_RELEASE, andDAGGER_NO_NAGto hide the Dagger Cloud signup hint. Bootable sends no traces to Dagger Cloud unless the user provides their ownDAGGER_CLOUD_TOKENor runsdagger login.installedruns GradleinstallDistineclipse-temurin:25-jdk, with the build cache in the Gradle-home cache volume;runtimeinstalls the app intoeclipse-temurin:25-jre;aot-cachetrains in a container of that runtime;imageis that same runtime plus the cache, so the JDK build and the jar mtimes match by construction;verifyfails unless at least 90% of the start's classes come from the cache, andcheck(@check) runs it;dev(@up) runs the image fordagger start.dagger.lockpins both images by digest. The image is exported (image export --path=…), never pushed.README: a "Faster Start: the JVM AOT Cache" section, including when to use each of the three, plus notes in the example's README.
Where the task lives, and why
It is a binary plugin in an included
build-logicbuild, not root-buildsubprojects {}logic or a script plugin:id("bootable.aot-cache");AotCacheTrainingdirectly with apodman runcommand);AotCache.ktinto its ownbuildSrc.Things found on the way
cp -a) and still use the cache.installDist, gives "This file is not the one used while building the AOT cache", and the app runs without the cache.containerizingMode = "packaged", because the JVM won't use a cache with a non-empty directory like/app/classeson the class path;-XX:AOTCacheand-XX:AOTCacheOutputcan't be combined.aotCachestays UP-TO-DATE. Jib'sdockerClient.executablemust be an absolute path, so the build resolves-PcontainerCli=podmanonPATH.OTEL_EXPORTER_OTLP_*in every exec, and forwards that telemetry to Dagger Cloud when logged in. The training,verifyanddevunset those variables, so the app exports nothing. Without that, the cache also picked up about 1,200 OTLP-exporter classes the app doesn't load in production.${…}inside"""strings as its own interpolation, so the module's shell scripts avoid shell brace expansions.-XX:AOTMode=onturns that into a startup failure.Measurements (median of 7, JDK 25)
=> Runningboot→=> Runningboot→ services startingPUT /entries/x=> Running=> Runningboot→=> Runningverifyreports 8,253 of 8,400 classes from it, and-Xlog:aotinpodman runshowed "Opened AOT cache /app/aot/vanilla.aot".Testing
./gradlew buildpasses, after rebasing onto master.:examples:server-ktor-db:vanilla:aotCacheand:examples:server-ktor-db:jib:jibDockerBuild -PcontainerCli=podmanwere run locally with rootless Podman.dagger check,dagger api call server-ktor-db verifyandimage exportwere run with Dagger v1.0.0-beta.28 on rootless Podman, with no Dagger Cloud login. The exported image was timed withpodman run.