Skip to content

Start the JVM from an AOT cache built with the image (~40% faster) - #227

Open
iHiD wants to merge 1 commit into
mainfrom
faster-startup
Open

iHiD wants to merge 1 commit into
mainfrom
faster-startup

Conversation

@iHiD

@iHiD iHiD commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Hello 🙂 I'm working with Claude to try and get our tooling faster.

This PR makes this project around 40% faster. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explains stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...


What changed

The image now ships a cache of the classes every run needs, already loaded and linked, and the JVM uses it at start-up. The JDK calls this an ahead-of-time (AOT) cache. Before this change, every run started a fresh JVM. Each JVM spent more than a second on start-up work before it touched the student's code. It found, loaded and linked the classes of javac, JUnit and AssertJ, and ran their code in the interpreter. For bob, that start-up work took about 1.5s of a 3.4s run.

When the image is built, the new script bin/create-aot-cache.sh runs the test runner once on a sample exercise in aot-training/, with the JVM flag -XX:AOTCacheOutput. The sample has tests that pass, fail and throw, and it uses parameterized tests, printed output and task tags. This makes the training run load the same classes as a typical student run. The JVM saves those classes in java-test-runner.aot, already loaded and linked, with profiling data about how their methods ran. The cache is built in the final image stage, with the same JDK used at run time. bin/run.sh now passes the cache to the JVM with -XX:AOTCache, so each run starts with those classes already loaded.

Long-running tests keep their speed. This change leaves the JIT compilers and the garbage collector alone, and the CPU-heavy exercises (such as alphametics) took the same time as before when measured.

The cache adds about 50 MB to the image (from 432 MB to 485 MB).

If the cache is missing or can't be used, the JVM will print a warning to stderr and run without it, at the old speed. The warning doesn't reach results.json.

This has been tested in production, and has reduced the median run from 3.5s to 2.0s.

🤖 Generated with Claude Code

Every run spent more than a second loading and linking the classes of
javac, JUnit and AssertJ before it compiled or ran any tests. When the
image is built, bin/create-aot-cache.sh now runs the test runner once on
a sample exercise in aot-training/ with -XX:AOTCacheOutput. The JVM saves
the classes loaded during that run, already loaded and linked, in
java-test-runner.aot. bin/run.sh passes that cache to the JVM with
-XX:AOTCache, so each run starts from that state. If the JVM can't use
the cache, it will print an error and run as before.

This takes the median run over the track's 169 example solutions from
3.36s to 1.90s, with identical results. The image grows by about 50 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iHiD
iHiD requested a review from a team as a code owner November 18, 2026 03:39
@iHiD iHiD changed the title Start the JVM from an AOT cache built with the image Start the JVM from an AOT cache built with the image (~40% faster) Nov 18, 2026
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.

1 participant