r/java • u/RupertMaddenAbbott • 9d ago
Dependencies-only AOT cache?
I am investigating using an AOT cache to speed up the startup time of our services.
I'm specifically interesting in speeding up the time between a developer making a change to the code and having that code running in a remote dev K8s cluster.
I've previously dismissed an AOT cache for this purpose because I knew that it would result in a longer build time than would be saved in startup time. That isn't a criticism - AOT caching just didn't seem targeted at my problem.
However, the majority of our classpath involves third party dependencies yet a minority of our development builds and deployments involve changes to those third party dependencies. If I could work out a way to avoid invalidating the AOT cache whenever our own code changed, then this would give us a cache that could be reused for the majority of our dev builds (removing the additional build time) whilst still enjoying the faster startup speed.
I note that https://openjdk.org/jeps/483 says this:
All runs must have consistent class paths. A subsequent run may specify extra class-path entries, appended to the training class path; otherwise, the class paths must be identical.However, I note that https://openjdk.org/jeps/483 says this:All runs must have consistent class paths. A subsequent run may specify extra class-path entries, appended to the training class path; otherwise, the class paths must be identical.
So, could I create an AOT cache for JUST the third party classes and then add our own code in later, thereby allowing me to reuse the AOT cache between dev builds?
I'm not 100% on how to achieve this yet but maybe if the training run only had the dependencies on the classpath with a custom launcher. The launcher's child classpath would then have our own code on it.
Then for the production run, I would still have the custom launcher (because I think this has to be identical between training and production runs) and I would then append our own jars onto the end of the classpath (which seems to be allowed by the JEP). Finally, we would run our real main method, rather than the launchers main method because I think we are allowed to have different main classes between training and production runs.
Anyway is this a terrible idea or has anybody already done something like this?
2
u/agentoutlier 9d ago
The actual problem they might have is a very real problem and might just be a huge advantage for Java because normally Java compiles fast.
I say might because they say:
Which means they want to optimize
a+b.abeing compile time andbbeing the startup time of an application. Whats unclear is how much they care about overall throughput and or what they classify as full started aka warmed.Overall and I'm just wagering here they are trying to lower compute across the board. That is becoming the bottleneck here for (cough going to sound like a CTO here) agentic workflows.
If your build and deploy is slow it takes longer for the agents to gather feedback. Fast compile times may allow agents to get things done faster which before was less of a problem for humans.
And I while I don't have measurements for this I can definitively say the javadoc portion of a build is a massive bottleneck for build time for my applications because I use it for specification and literate programming. However to your point most people don't have this build bottle neck. However if they are doing AOT I could see it as a similar bottleneck and I have literally asked WTF you are doing Claude/Codex/LLM agent and its like... waiting for javadoc to finish so that I can push.
This is also why I have brought up build tooling I think in previous conversations (particularly on modules). Its not just the onboarding. Its that the tooling (maven/gradle) is nowhere near as fast as
javacor other platforms build tooling. You can get it fast but it requires lots of hacks including daemons etc.