JEP 483: Ahead-of-Time Class Loading and Linking
openjdk.org
openjdk.org
And for the bigger applications (like web services and alike), you don't really care that it takes 5 seconds or 10 seconds to start it, you only restart the server during deployment anyways, so why would startup time matter so much?
One of the use cases for startup time is AWS lambda and similar.
[1] https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
Of course, I wouldn't be surprised if the boffins at lambda add some integration between snapstart and class caching once their leadership can get it funded
Eg SnapStart only works on AWS, not on other FaaS platforms, even there needs extra cloud infra fiddlery and costs extra.
Sure, my comment was more about the relative improvement. In the case of the 0.031s example (which is the number without the improvement), it gets down to 0.018s with this new AOT class loading. What value do you get from something starting in 0.018s instead of 0.031s? The difference is so marginal for that particular use case.
> One of the use cases for startup time is AWS lambda and similar.
I suppose that's one use case where it does make sense to really focus on startup times. But again, I'd rather use something that fast startup already exists (Babashka, ClojureScript) instead of having to add yet another build-step into the process.
If you're on higher FPS monitors, the budget shrinks accordingly. At 60fps you'll have 16ms, at 480fps you'll have 2ms.
The same applies for any app that should feel like it starts instantly.
Agreed - I've got some JVM Lambdas that are quite slow to start (it doesn't take many libraries to make a heavy Lambda).
Someone else mentioned SnapStart which I think came out this year but there are enough caveats that I'm reluctant to try it in anger (big inherited code base that has shoved way too much into Lambda).
IMHO, while optimizations in the JVM are always welcome, they primarily address surface-level issues and don't tackle Clojure's core limitation: the lack of a proper tree shaker that understands Clojure semantics. Graalvm offers help here by doing whole-program optimization at the bytecode level, but a Clojure-specific tree shaker could take things further: it could eliminate unused vars before/during Clojure AOT, thereby reducing both program size and startup time. These improvements would happen before the JVM optimizations kick in, making everything that follows a nice extra bonus.
[1] https://www.lispworks.com/documentation/HyperSpec/Body/s_dec...
Also, I guess Java-based desktop applications like IntelliJ and DBeaver will benefit.
"Learning about babashka (bb), a minimalist Clojure for building CLI tools"
So I think you’re right.
So a bit more linker style optimization than compiler related caching stuff.
"The AOT cache builds upon CDS by not only reading and parsing class files ahead-of-time but also loading and linking them."
While CDS (which has been available for years now) only caches a parsed form of the class files that got loaded by the application, the AOT cache will also "load and link" the classes.
The ClassLoader.load method docs explain what loading means: https://docs.oracle.com/en/java/javase/21/docs/api/java.base...
1. find the class (usually by looking at the file-index of the jar, which is just a zip archive, but ClassLoaders can implement this in many ways).
2. link the class, which is done by the resolveClass method: https://docs.oracle.com/en/java/javase/21/docs/api/java.base... and explained in the Java Language Specification: https://docs.oracle.com/javase/specs/jls/se21/html/jls-12.ht...
"Three different activities are involved in linking: verification, preparation, and resolution of symbolic references."
Hence, I assume the AOT cache will somehow keep even symbolic references between classes, which is quite interesting.
As another possible mismatch, suppose an AOT code asset is compiled to use a specific level of ISA, such as Intel’s AVX-512, but the production run takes place on a machine that does not support that ISA level. In that case the AOT code asset must not be adopted. Just as with the previous case of a devirtualized method, the presence of AVX-512 is a dependency attached to the AOT asset which prevents it from being adopted into the running VM.
Compare this with the parallel case with static compilers: A miscompiled method would probably lead to a crash. But with Java, there is absolutely no change to program execution as a result of the mismatch in ISA level in the CDS archive. Future improvements are possible, where the training run may generate more than one AOT code asset, for a method that is vectorized, so as to cover various possibilities of ISA level support in production.
Also: https://openjdk.org/projects/leyden/[1] https://openjdk.org/projects/leyden/
And Android while not being a Java/JVM proper, more of a cousin, also has similar JIT cache concept as intermediate step before doing AOT compilation of selected code.
Naturally also welcomed on the OpenJDK distributions.
That’s not immediately convincing that it will be worth it. It is a start I guess.
RAM is almost free if you’re not on embedded, and embedded could run Java sure, but it isn’t common.
It's nice to at least have the option of making that tradeoff
(And I suspect for plenty of applications, the class cache will be worth more time than (an also probably cached) image pull)
If image size is a concern, I imagine a native binary using GraalVM would’ve been a better way out anyhow, and you’ll bypass this cache entirely.
At current RAM prices you'd expect the smallest instances to have 2GB, yet they still charge $4/month for 512MB, which isn't enough to run the average JVM web server.
I'd assume they are very aware of demand levels for different types and would be adjusting the configurations if needed.